繁体   English   中英

需要有关.htaccess url重写国家特定子目录网址的帮助

[英]Need help regarding .htaccess url rewriting for country specific subdirectory urls

我正在制作一个项目,用于建立一个包含国家特定网址的网站,使其更具针对性和独立性。

这就是我想要的:

  1. open - domain.com并读取此文件index.php

  2. 当打开domain.com/us/并读取此文件country.php(/ us /它可以是/ de / / in / / uk /表示根据请求动态生成的国家/地区代码)。

  3. 当打开domain.com/us/free-free-free-ad1965.html(其网站上的帖子,ID为1965,来自数据库,所以它应该读取ad.php文件。

  4. 如果打开domain.com/xyz不存在则应该给出404错误并且读取404.php文件同样适用于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选项后,每次都可以正常工作,选项2和3&4彼此冲突。 所有四个选项都是分开的,应该相互协作。

请帮帮我,我该怎么做?

规则的具体程度如何更具体。

你应该改变顺序。

rewriteRule ^(。 )/(。 ) - ad(。*)。html ad.php?countrycode = $ 1&post = $ 2&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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM