【发布时间】:2014-08-13 09:50:03
【问题描述】:
我已经尝试并查找了很多您的帖子, 还不能让它工作。
来自网站的所有 URL 我有一个简单的 PHP 配置,像这个例子:
http://www.example.com/index.php?page=pagename
我想知道是否可以像这样隐藏 Quesry_String:
http://www.example.com/pagename/
在服务器配置中(apache 2.2 使用没有 .htaccess 的虚拟主机):
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]
我想我快到了,谢谢你的帮助。
【问题讨论】:
标签: rewrite query-string