我无法理解,也无法找到所需的明确信息。
是否可以使用mod_rewrite localhost/mysite/index.php?a=search
url重写为localhost/mysite/search
?
我尝试过维基百科http://en.wikipedia.org/w/index.php?title=Dog
,然后立即重定向到https://en.wikipedia.org/wiki/Dog
。我想要类似的东西。
我在我的localhost网站.htaccess文件中试过这段代码:
RewriteRule ^([a-z]+)/?$ index.php?a=$1 [NC,L]
当我尝试输入类似localhost/mysite/search
的浏览器时它起作用,但它只是我想要的一部分。请回答,我已经筋疲力尽了。
答案 0 :(得分:0)
您需要一个额外的重定向规则才能重定向到漂亮的网址。这样做:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?a=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
RewriteRule ^([a-z]+)/?$ index.php?a=$1 [NC,L,QSA]