2016-06-30 52 views
1

我正在制作一个项目,使网站包含国家特定的网址,使其更具针对性和分离。需要关于.htaccess网址重写国家特定的子目录网址

这里我想要什么:

  1. 开放 - domain.com和读取该文件的index.php

  2. 打开时domain.com/us/和读取该文件country.php(/我们/它可以是任何类似/ de// in// uk /意思是基于请求动态生成的国家/地区代码

  3. 当打开域名/us/free-free-free-ad1965.html(其在网站上发布ID为1965的数据库,所以它应该阅读ad.php文件。

  4. ,如果它不存在,它应该给404错误和读取404.php文件相同的开放domain.com/xyz适用于domain.com/us/xyz

这里是我当前的htaccess代码:

Options +FollowSymlinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^domain.com [NC] 
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 
RewriteRule ^(.*)/ country.php?countrycode=$1 [NC] 
RewriteRule ^(.*)/(.*)-ad(.*).html ad.php?countrycode=$1&post=$2&id=$3 [NC] 
RewriteRule ^maintenance\.html$ maintenance.php [NC,L] 
RewriteRule ^submit\.html$ submit.php [NC,L] 
RewriteRule ^privacy\.html$ privacy.php [NC,L] 
RewriteRule ^terms\.html$ terms.php [NC,L] 
RewriteRule ^contact\.html$ contact.php [NC,L] 

ErrorDocument 400 /404.php 
ErrorDocument 401 /404.php 
ErrorDocument 403 /404.php 
ErrorDocument 404 /404.php 
ErrorDocument 500 /404.php 

应用此htaccess的选项1件作品细每次和选项后2 4与彼此冲突。所有四个选项是分开的,并且应该相互协作。

请帮我,我该怎么做?

回答

0

这条规则应该如何更具体一些。

您应该更改订单。

重写规则^()/()-α(*)。HTML ad.php?COUNTRYCODE = $ 1 &后= $ 16 & ID = $ 3 [NC] 也许应该多了起来

Options +FollowSymlinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^domain.com [NC] 
RewriteRule ^(.*)/(.*)-ad(.*).html ad.php?countrycode=$1&post=$2&id=$3 [NC] 
RewriteRule ^(.*)/$ country.php?countrycode=$1 [NC] 
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 


RewriteRule ^maintenance\.html$ maintenance.php [NC,L] 
RewriteRule ^submit\.html$ submit.php [NC,L] 
RewriteRule ^privacy\.html$ privacy.php [NC,L] 
RewriteRule ^terms\.html$ terms.php [NC,L] 
RewriteRule ^contact\.html$ contact.php [NC,L] 

ErrorDocument 400 /404.php 
ErrorDocument 401 /404.php 
ErrorDocument 403 /404.php 
ErrorDocument 404 /404.php 
ErrorDocument 500 /404.php 
+0

好吧,我试过了,但没有运气。当请求“http:// www.domain.com/us /'它给予'http://www.domain.com/country.php/?countrycode = country.php'并且在请求http:// www。 domain.com/us/free-free-free-ad1965.html'即时获取错误为:该页面没有正确重定向 Firefox检测到服务器正以一种永远不会完成的方式重定向该地址的请求。 –

+0

好吧,我认为它的工作现在,问题是301重定向代码行我改变了自己的立场,现在它的工作。 '.rewriteRule ^(。*)/'$').http://www.domain.com/$1 [L,R = 301]' 'RewriteRule ^(。*)/ (*。) - ad(。*)。html ad.php?countrycode = $ 1&post = $ 2&id = $ 3 [NC]' 'RewriteRule ^(。*)/ $ country.php?countrycode = $ 1 [NC]' –