301.htaccess重定向简单的工作301的.htaccess我活的服务器上重定向看起来是这样的:不能在XAMPP
Options +FollowSymLinks
RewriteEngine on
redirect 301 /test.php /index.php
但我不能让它工作,我的XAMPP安装。 我在http.conf文件中启用了mod_rewrite.so,我看不出为什么它不重定向。重新启动了Apache但没有运气。
301.htaccess重定向简单的工作301的.htaccess我活的服务器上重定向看起来是这样的:不能在XAMPP
Options +FollowSymLinks
RewriteEngine on
redirect 301 /test.php /index.php
但我不能让它工作,我的XAMPP安装。 我在http.conf文件中启用了mod_rewrite.so,我看不出为什么它不重定向。重新启动了Apache但没有运气。
为了让你知道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
工作。
通过创建本地域使用Apache Virtual Hosts来实现它。一旦本地域设置,重定向代码就像它在现场服务器上一样工作:
redirect 301 /test.php /test2.php.php
谢谢 - 代码确实有效,但有一个问题我没提到! 工作正常,但在本地,index.php带我回到DocumentRoot,而不是网站的主页。如果我将index.php更改为“/home/sitefolder/public_html/index.php”,它就会起作用,但那不起作用。 我想为本地和活动服务器使用相同的.htaccess文件。 – monkey64
在本地服务器上您的DocumentRoot是什么,它为什么与您的网站的主页有所不同? – anubhava
XAMPP上的DocumentRoot是“E:/”,与现场服务器明显不同。问题是为什么我的原始代码[redirect 301 /test.php /index.php]在live web上完美工作,但在本地失败。我需要做些什么才能在XAMPP中使用它? – monkey64