2014-09-25 253 views
1

我想要ajax/file地址被重定向到ajax/file.php使用.htaccess。我創建了一個如下所示的.htaccess文件,但是這會導致500內部服務器錯誤。htaccess重寫url文件夾/文件到文件夾/ file.php

RewriteEngine On 
RewriteRule ^ajax/(.*)$ ajax/$1.php [L] 

另外一個信息是我的網站在一個子文件夾下工作。 (本地主機/ myproject的)RewriteRule ^ajax/(.*)$ /ajax/$1.php [L]重定向的URL(本地主機/ AJAX/file.php),而不是(本地主機/ myproject的/ AJAX/file.php

回答

1

問題是,在.*您正則表達式也匹配file.php

使用您的規則是這樣的:!

Options -MultiViews 
RewriteEngine On 

RewriteRule ^ajax/([^./]+)/?$ ajax/$1.php [L] 
+2

和'[^ /] +'應該是選擇文件只在file.php謝謝它工作得很好 – 2014-09-25 19:47:03

+0

不客氣,很高興它的工作。 – anubhava 2014-09-25 20:03:52