簡體   English   中英

mod重寫規則不起作用-apache .htaccess

[英]mod rewrite rule won't work - apache .htaccess

我有一個簡單的Flask應用程序,我更改了Apache配置文件以啟用.htaccess,並且我假設該文件被Apache看到,就像我在.htaccess中編寫“所有人拒絕”時得到的是“禁止”頁面。 這使我認為語法中一定有錯誤。 我花了很多時間嘗試使用其他RegEx,但無濟於事。

我想轉換當前網址:

http://example.com/average_temperatures?city1=istanbul&city2=ankara&city3=倫敦

采用這種格式:

http://example.com/average_temperatures/istanbul/ankara/london

這是我的.htaccess的內容:

RewriteEngine On 

RewriteRule ^average_temperatures/([^/.]+)/([^/.]+)/([^/.]+)/?$ average_temperatures?city1=$1&city2=$2&city3=$3 [L]

有人可以指示我正確的方向嗎? 我感謝任何提示。 謝謝。

使用這個可愛的站點調試htaccess規則: http : //htaccess.madewithlove.be/-因此,您的規則匹配。 所以問題是另外一回事。 (也許您誤解了URL重寫的目的?)

您的規則完美地重寫了EXTERNAL請求

http://weather-averages.co.uk/average_temperatures/istanbul/ankara/london

http://weather-averages.co.uk/average_temperatures?city1=istanbul&city2=ankara&city3=london 

請記住,此規則不適用於放置在html中的鏈接。 您需要更改您的<a href="">以定位SEO網址,您要提供:

<a href="http://weather-averages.co.uk/average_temperatures/istanbul/ankara/london">

然后將被重寫,這樣您就可以使用以下$_GET -Array:

$_GET = array (
   "city1" => "istanbul",
   "city2" => "ankara",
   "city3" => "london"
);

ps:在您的重寫規則上,您缺少擴展名-也許這是您的問題?

average_temperatures?city1=$1&city2=$2&city3=$3 [L]
average_temperatures.php?city1=$1&city2=$2&city3=$3 [L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM