用htaccess重写url?page = 2到/ page / 2?

时间:2013-02-14 12:53:10

标签: php .htaccess url-rewriting

如何为目录photos重写我的网址

http://www.abc.com/photos/index.php?page=2http://www.abc.com/photos/page/2

我的.htaccess

# Turn mod_rewrite on
RewriteEngine on
RewriteBase /
...

4 个答案:

答案 0 :(得分:3)

RewriteRule ^photos/page/([0-9]+) index.php?page=$1

答案 1 :(得分:1)

RewriteRule ^photos/index.php?page=([0-9]*)$ /photos/page/$1 [R=301,L]

答案 2 :(得分:1)

你没有提到哪些字符串是动态的,所以我假设这个答案page2是可变的。

你可以试试这个:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php                 [NC]
RewriteCond %{REQUEST_URI} ^/photos/([^/]+)/([^/]+)/?  [NC]
RewriteRule .*      photos/index.php?%1=%2          [L,QSA]

内部地图

带有或不带斜线的

http://www.abc.com/photos/key/val

要:

http://www.abc.com/photos/index.php?key=val

假设字符串keyval是可变的,而假设photos是固定的。

对于永久性和可见的重定向,请将[L,QSA]替换为[R=301,L,QSA]

答案 3 :(得分:0)

RewriteEngine On
RewriteRule ^photos/page/([a-zA-Z0-9-/]+)$ photos/index.php?page=$1 [QSA]
RewriteRule ^photos/page/([a-zA-Z0-9-/]+)/$ photos/index.php?page=$1 [QSA]