重写url?page=2到/page/2(使用htaccess)


rewrite url ?page=2 to /page/2 with htaccess?

如何为目录photos重写我的url,ONLY

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

我的.htaccess

# Turn mod_rewrite on
RewriteEngine on
RewriteBase /
...
RewriteRule ^photos/page/([0-9]+) index.php?page=$1
RewriteRule ^photos/index.php?page=([0-9]*)$ /photos/page/$1 [R=301,L]

您没有提到哪些字符串是动态的,所以我假设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]

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]