我正在尝试过滤一个2层级别的子域到我的网站。
表格如下:
country.category.mywebsite.com ~其中国家/地区为2个字符。
我正在尝试为3种排列设置一个重写规则:
-[country].[category].mywebsite.com = mywebsite.com?country=%1&category=%2
-[category].mywebsite.com = mywebsite.com?category=%1
-[country].mywebsite.com = mywebsite.com?country=%1以下是我目前所拥有的。
RewriteCond %{HTTP_HOST} !www.mywebsite.com$ [NC] # Presuming you don't want to do www
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.mywebsite\.com [NC] # Catch subdomain
RewriteCond %{REQUEST_URI} !\.(?:jpe?g|png|gif|bmp|php)$ [NC]
RewriteRule ^(.*)$ index.php?country=%1&category_subs=%2 [QSA,L]我不确定是否有任何方法来过滤正则表达式的长度,以便我可以过滤所有2字符子域名从国家。
任何帮助或建议都非常感谢。谢谢。
发布于 2016-10-21 21:22:16
这些可能会让您开始(根据需要添加标志和其他条件):
RewriteCond %{HTTP_HOST} ^(\w\w)\.(\w+)\.mywebsite\.com [NC]
RewriteRule ^(.*)$ index.php?country=%1&category=%2
RewriteCond %{HTTP_HOST} ^(\w\w)\.mywebsite\.com [NC]
RewriteRule ^(.*)$ index.php?country=%1
RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com [NC] # Note: this will also rewrite the country URL if you don't [END] there
RewriteRule ^(.*)$ index.php?category=%1https://stackoverflow.com/questions/40177676
复制相似问题