我面临的问题是我有一个外卡域,我希望将所有子域重定向到特定的URL,即
http://subdomain.domain.com - > http://www.domain.com/pagination.php?id=subdomain&page=1
同样如果
http://subdomain.domain.com/page-2 - > http://www.domain.com/pagination.php?id=subdomain&page=2
如果给出产品ID,即
http://subdomain.domain.com/some_product_name-123 - > http://www.domain.com/productview.php?id=123
我的htaccess文件是
RewriteCond %{http_host} .
RewriteCond %{http_host} !^www.pricesinpakistan.com.pk [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan.com.pk [NC]
RewriteRule page-^([^/]*)$ pagination.php?id=%1&page=$2 [L]
RewriteRule ^(.*)$ pagination.php?id=%1&page=1 [L]
以上规则不符合页面规则所有重定向都在最后一条规则上完成,空字符串为id。
答案 0 :(得分:1)
RewriteCond
仅适用于下一个RewriteRule
。 ^
。^$
作为URI模式。请改用此规则:
RewriteCond %{http_host} !^www\.pricesinpakistan\.com\.pk$ [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan\.com\.pk$ [NC]
RewriteRule ^page-(\d+)/?$ pagination.php?id=%1&page=$1 [NC,L,QSA]
RewriteCond %{http_host} !^www\.pricesinpakistan\.com\.pk$ [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan\.com\.pk$ [NC]
RewriteRule ^$ pagination.php?id=%1&page=1 [L,QSA]
RewriteCond %{http_host} !^www\.pricesinpakistan\.com\.pk$ [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan\.com\.pk$ [NC]
RewriteRule ^(\w+)-(\d+)/?$ productview.php?catname=%1&productname=$1&productid=$2 [NC,L,QSA]