在htaccess文件中重写规则冲突?

时间:2012-10-25 09:44:03

标签: .htaccess mod-rewrite url-rewriting

我在htaccess文件中写了规则,但是两条规则相互冲突。 我的htaccess文件是:

# BEGIN REMOVE SLUG CUSTOM POST TYPE RULES
RewriteRule ^service-status/(.+)/$ /$1 [R=301,L]
RewriteRule ^country/(.+)/$ /$1 [R=301,L]
RewriteRule ^company/(.+)/$ /$1 [R=301,L]
# END REMOVE SLUG CUSTOM POST TYPE RULES


RewriteRule ^([a-zA-Z0-9_-]+)/numero/$ ?country=$1
RewriteRule ^introduction/([a-zA-Z0-9_-]+) ?company=$1
RewriteRule ^pays/(.+)?$ /pays?company=$1
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?country=$1&company=$2

# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /ade/
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /ade/index.php [L]
</IfModule>

# END WordPress
all rule working fine but 
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?country=$1&company=$2
RewriteRule ^([a-zA-Z0-9_-]+)/numero/$ ?country=$1
conflict each other both are working fine Individually   

我想要网址 1. http://abc.com/country-name/companyname/

(RewriteRule ^([^/]*)/([^/]*)/$ /index.php?country=$1&company=$2)

2.http://abc.com/country-name/numero/(numero是修复关键词)

RewriteRule ^([a-zA-Z0-9_-]+)/numero/$ ?country=$1

感谢您的帮助。 谢谢 巴鲁

1 个答案:

答案 0 :(得分:1)

试试这个:

# BEGIN REMOVE SLUG CUSTOM POST TYPE RULES
RewriteRule ^service-status/(.+)/$ /$1 [R=301,L]
RewriteRule ^country/(.+)/$ /$1 [R=301,L]
RewriteRule ^company/(.+)/$ /$1 [R=301,L]
# END REMOVE SLUG CUSTOM POST TYPE RULES


RewriteRule ^([a-zA-Z0-9_-]+)/numero/$ ?country=$1
RewriteRule ^introduction/([a-zA-Z0-9_-]+) ?company=$1
RewriteRule ^pays/(.+)?$ /pays?company=$1
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?country=$1&company=$2

# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /ade/
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /ade/index.php [L]
</IfModule>

# END WordPress
RewriteRule ^([a-zA-Z0-9_-]+)/numero/$ ?country=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?country=$1&company=$2 [L]