我想将页面从my_site.com/gamenews.php?id={ID}重定向到my_site.com/news/{ID}/,但无法:(
我的 .htaccess 文件:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/index.php /$1/index [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteRule ^gamenews.php?id=(.*) /news/$1/ [L,R]
AddDefaultCharset UTF-8
显示的错误:
无法处理请求"游戏新闻.php
我做错了什么?谢谢。
像这样尝试
RewriteRule ^news/([0-9]+)/ gamenews.php?id=$1[L,R]
- 重写的网址应该排在第一位
- [0-9] 表示第二个参数应为数字
除了语法之外,htaccess 规则的顺序可能是您的问题。除非我误解了你的问题。
试试这个在你的htaccess。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news/(.*) gamenews.php?id=$1 [L]
RewriteRule ^(.*)/index.php /$1/index [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
AddDefaultCharset UTF-8