2012-06-14 36 views
1

我正在使用良好的結果下面的代碼來訪問我的php文件的alla沒有指定擴展名到/ it目錄。換句話說,我可以訪問「http://www.mydomain.com/it/about.php」只寫「http://www.mydomain.com/it/about」使用 - 而不是_(下劃線)與.htaccess

Options -MultiViews 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ http://www.mydomain.com/it/$1.php [L] 

同樣發生時,我嘗試進入http://www.mydomain.com/it/question_answers.php。 如何直接訪問*「http://www.mydomain.com/it/question_answers.php」*還寫作「http://www.mydomain.com/it/question-answers」? 我在前面寫了下面的浮動代碼,但它似乎不起作用。

Redirect 301 /question-answer http://www.mydomain.com/it/question_answer.php 

,因爲如果我寫 「http://www.mydomain.com/it/question-answer」 瀏覽器嘗試打開該網頁: 「http://www.mydomain.com/it /question-answer.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php」

後的小摘要:

  • 我的頁面* 「http://www.mydomain.com/it/question_answers.php」 *
  • 與代碼的第一部分,我可以使用鏈接*「http://www.mydomain.com/it/question_answers」得到它*
  • 我想訪問同一頁面具有以下「http://www.mydomain.com/it/question-answers」

謝謝!

+0

轉到serverfault.com –

回答

0

這應該爲你工作:

Options -MultiViews 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ http://www.mydomain.com/$1.php 

RewriteRule it/question-answer\.php http://www.mydomain.com/it/question_answer.php [R=301,L] 

我已經改變了兩件事情:我在第一重寫規則的新的URL刪除it/。否則,您將被重定向到it/it/
我還將\.php添加到第二個RewriteRule。我不知道爲什麼,但RewriteRule似乎取代了模式而不是重定向。如果你的模式是it/question-answer而真實的網址是it/questions-answer.php.php不會被替換。