简体   繁体   中英

redirect to url based on php variable

I am getting a Internal 500 Error at present with my code below

What I have is a games site that calls it's games (around 100) with one single php file:

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

What I am trying to do is permanently redirect each game to its equivalent static .html page with the same name as the argument supplied in the above links in a new folder.

So the above would redirect to:

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

The code I currently have below is giving me internal 500 eror:

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

It seems like such a simple thing but I have tried countless variations with either internal error or page 404 or nothing at all.

You can use:

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]

To redirect
http://www.domain.com/game-play.php?content=GAME1
to
http://www.domain.com/game/GAME1.html

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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