繁体   English   中英

重定向到基于PHP变量的URL

[英]redirect to url based on php variable

我现在在以下代码中收到Internal 500 Error

我拥有的是一个游戏网站,该网站使用一个单独的php文件将其称为游戏(大约100个):

game-play.php?content=GAME1
game-play.php?content=GAME2
game-play.php?content=GAME3

我想做的是将每个游戏永久重定向到其等效的静态.html页面,其名称与新文件夹中以上链接中提供的参数相同。

因此,以上内容将重定向到:

/games/GAME1.html
/games/GAME2.html
/games/GAME3.html

我目前在下面的代码给了我内部500错误:

RewriteCond %{QUERY_STRING} content=([^/]+)/?  [NC]
RewriteRule ^/?  /games/?content.html [L,NC]

看起来像是一件简单的事情,但是我尝试了无数种形式的内部错误或页面404或根本没有任何变化。

您可以使用:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+game-play\.php\?content=([^\s&]+) [NC]
RewriteRule ^ /games/%1.html? [R=301,L]

RewriteRule ^games/([^./]+)\.html$ /game-play.php?content=$1 [L,QSA,NC]

重定向
http://www.domain.com/game-play.php?content=GAME1

http://www.domain.com/game/GAME1.html

尝试:

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /game-play.php?content=$1 [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM