我需要将country.cfm?country = xxx更改为xxx.html,并将hotel.cfm?hotel = yyy更改为yyy.html
我的.htacess文件中包含以下内容:
# change all the country pages
RewriteRule ^([^/]*)\.html$ /country.cfm?country=$1 [L]
# change all the hotel pages
RewriteRule ^([^/]*)\.html$ /hotel.cfm?hotel=$1 [L]
问题在于该国家/地区正在运作,但没有酒店。如果我把旅馆改写在该国之前,那么该旅馆就可以工作,但不能在该国工作。
如果我去hotel.cfm?hotel = yyy,那么如果我交换重写器,我将被重定向到country.cfm,反之亦然。
因为您使用的是完全相同的重写规则。当规则同时匹配时,引擎如何知道XXX.html是国家/地区和YYY.html是酒店?由于您拥有该L
标志,因此不会处理下一个标志。
例如,您需要在URL中有一些区别hotel-XXX.html
,然后进行匹配。然后您的重写将起作用。
例如:
# change all the country pages
RewriteRule ^country-([^/]*)\.html$ /country.cfm?country=$1 [L]
# change all the hotel pages
RewriteRule ^hotel-([^/]*)\.html$ /hotel.cfm?hotel=$1 [L]
用于诸如之类的网址site.tld/hotel-name.html
,或者
# change all the country pages
RewriteRule ^country/([^/]*)\.html$ /country.cfm?country=$1 [L]
# change all the hotel pages
RewriteRule ^hotel/([^/]*)\.html$ /hotel.cfm?hotel=$1 [L]
对于像这样的网址 site.com/hotel/name.html
匹配部分的任何差异就足够了,即使开头是单个字母也是如此。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句