多国使用 .htaccess
Multi-Country Using .htacces
我正在努力实现以下任一目标:
http://ca.domain.com/Category/SubCategory
-> http://www.domain.com/index.php?country=ca&category=Category&subcategory=Subcategory
http://www.domain.com/ca/Category/SubCategory
-> http://www.domain.com/index.php?country=ca&category=Category&subcategory=Subcategory
我已经四处浏览,但遗憾的是未能找到任何可行的解决方案。对于第一种,我尝试了以下代码:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^(.*)/$ http://www.domain.com/index.php&country=%1&category= [L]
子域的问题是它根本不会重定向到任何地方。我四处阅读,它说我需要设置通配符虚拟主机。我一直无法弄清楚如何在godaddy上做到这一点。所以不知道该怎么做。
关于第二种,我使用了如下代码:
RewriteEngine on
RewriteRule ^(.*)/?(.*)/ home.php?country=&category= [B]
但这对我也不起作用。在这方面的任何帮助将不胜感激。谢谢
至于类别和子类别,子类别是强制性的。所以它也应该适用于以下 link:
http://www.domain.com/ca/Toronto/Programming
-> http://www.domain.com/index.php?country=ca&location=Toronto&subcategory=Programming
http://www.domain.com/ca/Programming
-> http://www.domain.com/index.php?country=ca&location=&subcategory=Programming
我不太确定如何告诉 .htaccess 它是 $1=subcategory 还是 $2=subcategory,因为它们在场景 1 和 2 中切换。
感谢@anubhava 的大力帮助,我取得了以下成就:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ adlisting.php?country=%1&category= [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ adlisting.php?country=%1&location=&category= [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?\.domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ adlisting.php?country=&category= [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?\.domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ adlisting.php?country=&category=&subcategory= [L,QSA,NC]
在 root .htaccess 中有这些规则:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?country=%1&category= [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?country=%1&category=&subcategory= [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ index.php?country=&category= [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ index.php?country=&category=&subcategory= [L,QSA,NC]
我正在努力实现以下任一目标:
http://ca.domain.com/Category/SubCategory
->http://www.domain.com/index.php?country=ca&category=Category&subcategory=Subcategory
http://www.domain.com/ca/Category/SubCategory
->http://www.domain.com/index.php?country=ca&category=Category&subcategory=Subcategory
我已经四处浏览,但遗憾的是未能找到任何可行的解决方案。对于第一种,我尝试了以下代码:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^(.*)/$ http://www.domain.com/index.php&country=%1&category= [L]
子域的问题是它根本不会重定向到任何地方。我四处阅读,它说我需要设置通配符虚拟主机。我一直无法弄清楚如何在godaddy上做到这一点。所以不知道该怎么做。
关于第二种,我使用了如下代码:
RewriteEngine on
RewriteRule ^(.*)/?(.*)/ home.php?country=&category= [B]
但这对我也不起作用。在这方面的任何帮助将不胜感激。谢谢
至于类别和子类别,子类别是强制性的。所以它也应该适用于以下 link:
http://www.domain.com/ca/Toronto/Programming
->http://www.domain.com/index.php?country=ca&location=Toronto&subcategory=Programming
http://www.domain.com/ca/Programming
->http://www.domain.com/index.php?country=ca&location=&subcategory=Programming
我不太确定如何告诉 .htaccess 它是 $1=subcategory 还是 $2=subcategory,因为它们在场景 1 和 2 中切换。
感谢@anubhava 的大力帮助,我取得了以下成就:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ adlisting.php?country=%1&category= [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ adlisting.php?country=%1&location=&category= [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?\.domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ adlisting.php?country=&category= [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?\.domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ adlisting.php?country=&category=&subcategory= [L,QSA,NC]
在 root .htaccess 中有这些规则:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?country=%1&category= [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?country=%1&category=&subcategory= [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ index.php?country=&category= [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ index.php?country=&category=&subcategory= [L,QSA,NC]