.htaccess - 删除查询字符串

时间:2015-06-09 00:27:45

标签: apache .htaccess mod-rewrite rewrite

目前访问者以这种方式查看我的网站:example.com/index.php?s = anyword+to +search

我想更改为example.com/anyword+to+search

我现在的.htaccess:

#!/usr/bin/env ruby
$stderr.sync = true

require 'optparse'

# default options
$configArg  = "./config/config.yml"
$typeArg = "Mag"
$envsArg = ['dark','snow']
$ledArg = false

# CHANGE HERE ! User global variables, not local variables.
# parse arguments
ARGV.options do |opts|
  opts.on("--config=val", String)          { |val| $configArg = val }
  opts.on("--type=val", String)            { |val| $typeArg = val }
  opts.on("--envs=['rain','dusk']", Array) { |val| $envsArg = val }
  opts.on("-l", "--led")                   { $ledArg = true }
  opts.parse!
end

print "ARGV => ", ARGV.join(', '), "\n"

# class that runs tests
class FlashLight

  def initialize(config, type, envs, led)  
    # Instance variables  
    @config = config  
    @type = type
    @envs = envs
    @led = led
  end  

  # CHANGE HERE ! You should use instance variables here, not local variables.
  def runTests
    puts "Running tests..."
    warn "config:   #{@config.inspect}"
    warn "type:      #{@type.inspect}"
    warn "envs:     #{@envs.inspect.to_s}"
    warn "led:  #{@led.inspect}"
  end

end

puts 'Creating new instance of FlashLight...'
# CHANGE HERE ! Use global variables.
flashlight = FlashLight.new($configArg, $typeArg, $envsArg, $ledArg) 
flashlight.runTests 

有谁知道怎么做?

2 个答案:

答案 0 :(得分:1)

尝试使用此规则将查询字符串重定向到短网址:

Options -Indexes +FollowSymLinks    
RewriteEngine On
RewriteBase /
#http to https   
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Query string to short url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/index\.php\?s=([^&\s]+) [NC]
RewriteRule ^ %1? [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ index.php?s=$1 [QSA,B,NC,L]

答案 1 :(得分:0)

尝试这样的事情:

RewriteRule ^(.*)$ /index.php?s=$1 [L]