我正在一个我想要网址
的网站上工作 www.example.com/directory1/states/california.php
指向
www.example.com/directory1/california
城市页面也有类似的网址更改:
www.example.com/directory1/cities/miami.php
应该指向
www.example.com/directory1/miami
我在访问文件中使用以下规则来更改网址:
RewriteRule ^directory1/(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|guam|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nationwide|nebraska|nevada|new_hampshire|new_jersey|new_mexico|new_york|north_carolina|north_dakota|ohio|oklahoma|oregon|pennsylvania|rhode_island|south_carolina|south_dakota|tennesee|texas|us_virgin_islands|utah|vermont|virginia|washington|west_virigina|wisconsin|wyoming)$ /directory1/states/$1.php [L]
RewriteRule ^directory1/(.*)$ /directory1/cities/$1.php [L]
但是,网址栏中没有任何变化,我总是找不到404。当我使用htaccess checker对其进行测试时,输出网址始终是正确的。我的规则出了什么问题?有没有办法测试mod_rewrite是如何运作的?
答案 0 :(得分:1)
某些服务器配置要求您在.htaccess文件中打开重写引擎。在顶部:
RewriteEngine on
我也知道一些服务器配置,其中文件路径以/开头/结尾(由于已经在请求上运行了其他重写规则),所以可能允许在规则中存在:
RewriteRule ^/?directory1/(alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|guam|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nationwide|nebraska|nevada|new_hampshire|new_jersey|new_mexico|new_york|north_carolina|north_dakota|ohio|oklahoma|oregon|pennsylvania|rhode_island|south_carolina|south_dakota|tennesee|texas|us_virgin_islands|utah|vermont|virginia|washington|west_virigina|wisconsin|wyoming)/?$ /directory1/states/$1.php [L]
RewriteRule ^/?directory1/(.*)/?$ /directory1/cities/$1.php [L]