如何启用apache重写步骤

时间:2013-10-08 14:30:40

标签: apache .htaccess mod-rewrite url-rewriting

我正在为Apache URL重定向编写脚本。

我研究了要写的重写规则。

现在我想知道实现这个的程序。

  1. 在http.conf中启用mod_rewrites

    LoadModule rewrite_module modules/mod_rewrite.so 
    AddModule mod_rewrite.c
    
  2. 我创建了.htaccess

  3. 现在我不确定以下内容。

     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 个答案:

答案 0 :(得分:0)

  

1.执行此操作所需的访问权限。

您需要对将要上传htaccess文件的文件夹具有写入权限,并且htaccess文件本身必须具有Web服务器的读取权限(很可能是“apache”用户)

此外,您至少需要:

AllowOverride FileInfo

在文档根目录的服务器配置中

  

2.放置.htaccess文件的位置

根据您拥有的规则,您希望它在文档根目录中。它在服务器配置中由DocumentRoot指令

表示
  

3.如何启用日志和写日志。

请参阅:http://httpd.apache.org/docs/current/mod/mod_log_config.html

特别是TransferLogErrorLog指令

  

4.我有两个网络服务器。我必须把它放在两个网站上。

为每个人做同样的事情。如果两个Web服务器都使用相同的文档根目录,那么显然您不需要将htaccess文件放在2个位置。如果它们具有不同的文档根,则将htaccess文件放在两个文档根目录中。