简体   繁体   English

.htaccess多个规则和例外

[英].htaccess multiple rules and exceptions

I have a .htaccess file that has multiple rules to make the url's look "pretty". 我有一个.htaccess文件,该文件具有多个规则以使url看起来“漂亮”。 This is the file: 这是文件:

RewriteEngine On

RewriteRule ^property/([^/]*)/?([^/]*)/?$ /property.php?ID=$1&Image=$2 [L]
RewriteRule ^property$ /property.php [L]

RewriteRule ^enquire/([^/]*)/?([^/]*)/?$ /enquire.php?ID=$1&Data=$2 [L]
RewriteRule ^enquire$ /enquire.php [L]

RewriteRule ^contact/?$ /contact.php [L]
RewriteRule ^home/?$ /index.php [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/(property|property/.*|enquire|enquire/.*|contact|contact/.*|home|home/.*)$
RewriteRule ^([^/]*)$ /custompages.php?ID=$1 [L]

The first set of rules works for property , enquire , contact and home . 第一组规则适用于propertyenquirecontacthome If the url is not one of these, eg www.foo.com/about-us , I want it to call the file custompages?ID=about-us but with this code, it isn't working. 如果该网址不是其中之一,例如www.foo.com/about-us ,我希望它调用文件custompages?ID=about-us但使用此代码,它将无法正常工作。 I am quite new to using .htaccess files and I can't figure out what the issue is myself. 我对使用.htaccess文件很陌生,但我不知道自己是什么问题。

Your last rule is not correct. 您的最后一条规则不正确。 Change that to: 更改为:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /custompages.php?ID=$1 [L]

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

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