2013-02-04 81 views
0

301.htaccess重定向簡單的工作301的.htaccess我活的服務器上重定向看起來是這樣的:不能在XAMPP

Options +FollowSymLinks 
RewriteEngine on 

redirect 301 /test.php /index.php 

但我不能讓它工作,我的XAMPP安裝。 我在http.conf文件中啓用了mod_rewrite.so,我看不出爲什麼它不重定向。重新啓動了Apache但沒有運氣。

回答

0

爲了讓你知道Apache的redirect指令來自mod_alias模塊,而不是來自more_rewrite模塊。點擊此處查看文檔:https://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect

如果你想用mod_rewrite來處理它,它然後使用它是這樣的:

RewriteEngine on 
RewriteRule ^test\.php$ /index.php [L,NC,R=301] 

或者使mod_alias中模塊使redirect工作。

+0

謝謝 - 代碼確實有效,但有一個問題我沒提到! 工作正常,但在本地,index.php帶我回到DocumentRoot,而不是網站的主頁。如果我將index.php更改爲「/home/sitefolder/public_html/index.php」,它就會起作用,但那不起作用。 我想爲本地和活動服務器使用相同的.htaccess文件。 – monkey64

+0

在本地服務器上您的DocumentRoot是什麼,它爲什麼與您的網站的主頁有所不同? – anubhava

+0

XAMPP上的DocumentRoot是「E:/」,與現場服務器明顯不同。問題是爲什麼我的原始代碼[redirect 301 /test.php /index.php]在live web上完美工作,但在本地失敗。我需要做些什麼才能在XAMPP中使用它? – monkey64

0

通過創建本地域使用Apache Virtual Hosts來實現它。一旦本地域設置,重定向代碼就像它在現場服務器上一樣工作:

redirect 301 /test.php /test2.php.php