我正在为 Apache URL 重定向编写脚本。
我已经研究了要编写的重写规则。
现在我想知道实现这个的过程。
-
在 http.conf 中启用mod_rewrites
LoadModule rewrite_module modules/mod_rewrite.so AddModule mod_rewrite.c
-
我创建了 .htaccess
现在我不确定以下内容。
1.Access rights required to do this.
2.The location to put .htaccess file
3.how to enable logs and write logs.
4.I have two web servers.Do I have to put this in both of them.
我的重写规则看起来像这样。
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} old_domain.com [NC]
RewriteRule ^(.*)$ http://www.new_domain.com/test$1 [L,R=301]
如果有人帮助我逐步执行此操作,那就太好了。
1.执行此操作所需的访问权限。
您需要对 htaccess 文件将要上传到的文件夹具有写入权限,并且 htaccess 文件本身必须具有网络服务器的读取权限(很可能是"apache"用户(
此外,您至少需要具备:
AllowOverride FileInfo
在文档根目录的服务器配置中
2.放置.htaccess文件的位置
根据您拥有的规则,您希望它在文档根目录中。它在服务器配置中由 DocumentRoot
指令表示
3.如何启用日志和写入日志。
请参阅:http://httpd.apache.org/docs/current/mod/mod_log_config.html
特别是TransferLog
和ErrorLog
指令
4.我有两个网络服务器。我必须把这个放在他们两个身上吗?
对每个人做同样的事情。如果两个Web服务器使用相同的文档根目录,那么显然您不需要将htaccess文件放在2个地方。如果它们具有不同的文档根目录,则将 htaccess 文件放在两个文档根目录中。