2015-09-28 150 views
1

我试图修改我的网站URL以获得更好的SEO。这是我到目前为止有:htaccess重写url匹配子域名

RewriteRule ^page-([0-9]+)/?$ /index.php?p=$1 [L,QSA,NC] 

我想要的http://www.domain.com/page-10 代替http://www.domain.com/index.php?p=10

但我怎么也匹配http://www.domain.com/category/index.php?p=2 它改写为http://www.domain.com/category/page-2

回答

3

您可以为/category/另一条规则:

RewriteRule ^(category)/page-(\d+)/?$ $1/index.php?p=$1 [L,QSA,NC] 

RewriteRule ^page-(\d+)/?$ index.php?p=$1 [L,QSA,NC] 

You e ven 将这两个规则合并成一个与此正则表达式。

RewriteRule ^(category/)?page-(\d+)/?$ $1index.php?p=$2 [L,QSA,NC] 
+0

“类别” 只是一个例子,也可以是另一个字符串(我有50个类别) – libertaire

+0

你可以使用:'RewriteRule ^([\ w - ] +)/ page - (\ d +)/?$ $ 1/index.php?p = $ 1 [L,QSA,NC]'作为第一条规则。 – anubhava

+0

我遇到了类似这样的URL的问题http://mysubdomain.domain.com/category/page-2 – libertaire

0

变化 http://www.domain.com/category/index.php?p=2http://www.domain.com/category/index.php?p=page-2 并重新写你的htaccess匹配:

Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^category/([0-9]+)-([a-z]+) http://www.domain.com/category/index.php?p=$1-$2 [NC]