多国使用.htacces多国、htacces

2023-09-02 09:55:49 作者:随风远走

我想达到以下任何一项:

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

我已经浏览各地可惜一直没能找出任何可行的解决方案。对于第一类我尝试以下code:

 选项+了FollowSymLinks
RewriteEngine叙述上

的RewriteCond%{HTTP_HOST} ^([^。] +)。域 .COM
重写规则^(。*)/ $ http://www.domain.com/index.php&country=%1&category=$1 [L]
 

使用子域名的问题是,它不重定向任何地方都没有。我看周围,它说我需要设置通配符的虚拟主机。我一直无法弄清楚如何做到这一点的GoDaddy的。所以不知道该怎么做。

对于第二种,我用下面的code:

  RewriteEngine叙述上

(。*)?(。*)?重写规则^ / / home.php全国1 = $&放大器;类= $ 2 [B]
 

但对我来说,要么没有工作。任何帮助在这方面将是非常美联社preciated。谢谢

至于分类和放大器;子目录,子目录是一种强制性的。因此,它也应该适用于以下链接:

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 =子类别或$ 2 =子类,因为它们在方案1和切换; 2。

由于巨大的帮助从@anubhava我已经达到了以下内容:

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /

的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{} REQUEST_FILENAME -d
重写规则^  -  [L]

的RewriteCond%{HTTP_HOST} ^((?!万维网。)[^。] +)。域 .COM $ [NC]
?重写规则^([^ /] +)/ $ adlisting.php国家=%1安培;类别= $ 1 [L,QSA]

的RewriteCond%{HTTP_HOST} ^((?!万维网。)[^。] +)。域 .COM $ [NC]
重写规则^([^ /] +)/([^ /] +)/ $ adlisting.php国家=%1安培;?1位置= $&放大器;类= $ 2 [L,QSA]

的RewriteCond%{HTTP_HOST} ^(WWW )?域 .COM $ [NC]
重写规则^([AZ] {2})1 /([^ /] +)/ $ adlisting.php国家= $&放大器;?类别= $ 2 [L,QSA,NC]

的RewriteCond%{HTTP_HOST} ^(WWW )?域 .COM $ [NC]
重写规则^([AZ] {2})/([^ /] +)/([^ /] +)/ $ adlisting.php国家= $ 1安培;?2类= $&安培;子类= $ 3 [L,QSA ,NC]
 
英国进口 HT544手持甚高频对讲机 海事VHF专用 T4防爆等级

解决方案

有根的.htaccess规则:

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /

的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{} REQUEST_FILENAME -d
重写规则^  -  [L]

的RewriteCond%{HTTP_HOST} ^((?!万维网。)[^。] +)。域 .COM $ [NC]
?重写规则^([^ /] +)/ $的index.php国家=%1安培;类别= $ 1 [L,QSA]

的RewriteCond%{HTTP_HOST} ^((?!万维网。)[^。] +)。域 .COM $ [NC]
重写规则^([^ /] +)/([^ /] +)/ $的index.php国家=%1安培;?1类= $&安培;子类= $ 2 [L,QSA]

的RewriteCond%{HTTP_HOST} ^(WWW )?域 .COM $ [NC]
重写规则^([AZ] {2})1 /([^ /] +)/ $的index.php国家= $&放大器;?类别= $ 2 [L,QSA,NC]

的RewriteCond%{HTTP_HOST} ^(WWW )?域 .COM $ [NC]
重写规则^([AZ] {2})/([^ /] +)/([^ /] +)/ $的index.php国家= $ 1安培;?2类= $&安培;子类= $ 3 [L,QSA ,NC]
 

I am trying to achieve any one of the following:

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

I have browsed around but unfortunately haven't been able to figure out any working solution. For the first kind I tried the following code:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^([^.]+).domain.com
RewriteRule ^(.*)/$ http://www.domain.com/index.php&country=%1&category=$1 [L]

The issue with sub domain is that it doesn't redirect anywhere at all. I read around and it says I need to setup wildcard virtual host. I haven't been able to figure out how to do that on godaddy. So not sure how to do it.

As for the second kind, I used the following code:

RewriteEngine on 

RewriteRule ^(.*)/?(.*)/ home.php?country=$1&category=$2 [B]

But that didn't work for me either. Any help in this regard would be highly appreciated. Thank you

As for Category & Subcategory, Subcategory is kind of mandatory. So it should also work for following 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

I am not quite sure as to how to tell .htaccess if it is $1=subcategory or $2=subcategory since they switch in scenario 1 & 2.

Thanks to immense help from @anubhava I have reached to the following:

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=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^((?!www.)[^.]+).domain.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ adlisting.php?country=%1&location=$1&category=$2 [L,QSA]

RewriteCond %{HTTP_HOST} ^(www.)?.domain.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ adlisting.php?country=$1&category=$2 [L,QSA,NC]

RewriteCond %{HTTP_HOST} ^(www.)?.domain.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ adlisting.php?country=$1&category=$2&subcategory=$3 [L,QSA,NC]

解决方案

Have these rules in 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=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^((?!www.)[^.]+).domain.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?country=%1&category=$1&subcategory=$2 [L,QSA]

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ index.php?country=$1&category=$2 [L,QSA,NC]

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ index.php?country=$1&category=$2&subcategory=$3 [L,QSA,NC]