0

我正在一个我想要网址的网站上工作

    www.example.com/directory1/states/california.php 

指向

    www.example.com/directory1/california

城市页面也有类似的 url 更改:

   www.example.com/directory1/cities/miami.php

应该指向

  www.example.com/directory1/miami

我在访问文件中使用以下规则来更改 url:

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 检查器对其进行测试时,输出 url 总是正确的。我的规则有什么问题?有没有办法测试 mod_rewrite 如何/是否正常运行?

4

1 回答 1

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]
于 2012-07-26T17:55:20.730 回答