问题是我有玩家壁纸的页面,当用户点击玩家名字时,他会进入页面:
player.php?name=Cristiano-Ronaldo
我按$_REQUEST['name']
获取名称值,我正在尝试重写:
mysite.com/player.php?name=Cristiano-Ronaldo
到
mysite.com/Football-Players/Cristiano-Ronaldo
我已经在网上阅读并尝试了很多建议而没有运气,这是我在.htaccess
中得到的最好的结果:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=([-a-zA-Z0-9_+]+)
RewriteRule ^players/player\.php$ /Football-Players/%1 [L,R=301]
RewriteRule ^Football-Players/%1 /players/player.php?name=%1 [L]
但我仍然得到404 Not found Error。
我在Windows 7上的wampserver上测试了这个
我该如何解决这个问题?
答案 0 :(得分:2)
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在.htaccess
目录下的DOCUMENT_ROOT
中:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+players/player\.php\?name=([^&\s]+) [NC]
RewriteRule ^ /Football-Players/%1? [R=301,L]
RewriteRule ^Football-Players/([^/]+)/?$ /players/player.php?name=$1 [L,QSA,NC]
答案 1 :(得分:0)
要确认您是否在wampserver中启用了rewrite_module
?您可以通过wampserver启用它 - > apache - >模块 - > rewrite_module