我试过并查找了很多帖子, 无法让它工作。
网站上的所有网址我都有一个简单的PHP配置,例如:
http://www.example.com/index.php?page=pagename
我想知道我是否可以像这样隐藏Quesry_String:
http://www.example.com/pagename/
在服务器配置中(使用没有.htaccess的虚拟主机的apache 2.2):
DocumentRoot "/home/account/www/www.mysite.com/"
Options -MultiViews
DirectoryIndex index.php
RewriteEngine On
## Rewrite 301 old Quesry_string (?p => ?page) ##
RewriteCond %{QUERY_STRING} ^p=([^&]+) [NC]
RewriteRule ^/$ /?page=%1 [R=301,L]
## Trying to hide query_string (not working) ##
#RewriteCond %{QUERY_STRING} ^page=([^&]+) [NC]
#RewriteRule ^/$ /%1 [R=301,L]
#result => http://www.www.mysite.com/pagename?page=pagename (404)
## Rewrite 301 old page names ##
RewriteCond %{QUERY_STRING} ^page=oldpagename$ [NC]
RewriteRule ^/index\.php$ /?page=pagename/ [R=301,L]
## Remove index.php from url ##
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
#Rewrite 301 index.html to root /
RewriteRule ^/index.htm?$ index.html [NC,R=301,L]
RewriteRule ^/index.html?$ / [NC,R=301,L]
我想我差不多了,谢谢你的帮助。
答案 0 :(得分:0)
它应该适合你,我猜
RewriteRule ^([^ /。] +)/ $ index.php?page = $ 1 [L]