我怎样才能重写我的网址,只为目录photos
?
http://www.abc.com/photos/index.php?page=2
至http://www.abc.com/photos/page/2
我的 .htaccess
# Turn mod_rewrite on
RewriteEngine on
RewriteBase /
...
我怎样才能重写我的网址,只为目录photos
?
http://www.abc.com/photos/index.php?page=2
至http://www.abc.com/photos/page/2
我的 .htaccess
# Turn mod_rewrite on
RewriteEngine on
RewriteBase /
...
RewriteRule ^photos/page/([0-9]+) index.php?page=$1
你没有提到哪些字符串是动态的,所以我假设这个答案是可变的page
。2
你可以试试这个:
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
字符串key
和val
假定是可变的,而photos
假定是固定的。
对于永久且可见的重定向,请替换[L,QSA]
为 [R=301,L,QSA]
.
RewriteRule ^photos/index.php?page=([0-9]*)$ /photos/page/$1 [R=301,L]
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]