.htaccess rewriterule用于更改URL

时间:2015-07-03 10:28:36

标签: php .htaccess

这是我目前的.htaccess:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
RewriteRule ^games/(.*)$ index.php?page=games&game=$1 [L,QSA]

我需要这个工作:

index.php?page =音乐应该是url.com/music

index.php?page =游戏应该是url.com/games

index.php?page = games& game = example应为url.com/games/example

请帮我写一下我的.htaccess

1 个答案:

答案 0 :(得分:0)

尝试以下

  Options +FollowSymlinks
    RewriteEngine on
    rewriterule ^index.php?page=music(.*)$ http://otherdomain.com/music$1 [r=301,nc]
rewriterule ^index.php?page=music(.*)$ http://otherdomain.com/music$1 [r=301,nc]
rewriterule ^index.php?page=games(.*)$ http://otherdomain.com/games$1 [r=301,nc]
rewriterule ^index.php?page=games&game=example(.*)$ http://otherdomain.com/games/example$1 [r=301,nc]