mod_rewrite in vhosts configuration

后端 未结 2 821
星月不相逢
星月不相逢 2020-12-17 20:05

I\'m trying to add mod_rewrite rules in the vhost config but it\'s not working. For the site \"mysite.com\" I want to redirect \"/webmedia/\" to the home page .

Here

相关标签:
2条回答
  • 2020-12-17 20:43
    <Directory /home/drupal_1>
      Options FollowSymLinks Includes ExecCGI
              AllowOverride All
              DirectoryIndex index.html index.htm index.php
    
      # Rewrite Rules #####################
      RewriteEngine On
      RewriteRule ^/webmedia/(.*) / [R=301,L]
      # end Rewrite Rules #################
    </Directory>
    

    This RewriteRule pattern would never match in a directory context (ie. inside a <Directory> container) because of the slash prefix. It would have needed to have been written like this:

    RewriteRule ^webmedia/ / [R=301,L]
    

    (The trailing (.*) was superfluous.)

    However, since it's in a <Directory> container, any mod_rewrite directives that you have in .htaccess (since you have AllowOverride All) could potentially override this.

    If you are using .htaccess and this is undesirable then probably better to take it out of the <Directory> container and have it directly in the <VirtualHost> container (a virtualhost context) - as @Seybsen has done in his answer.

    0 讨论(0)
  • 2020-12-17 20:50

    This should work if you have mod_rewrite loaded.

    <Directory /home/drupal_1>
        Options FollowSymLinks Includes ExecCGI
        AllowOverride All
        DirectoryIndex index.html index.htm index.php
    </Directory>
    <Directory /home/movies>
        Options FollowSymLinks Includes ExecCGI
        AllowOverride All
        DirectoryIndex index.html index.htm index.php
    </Directory>
    <VirtualHost 192.168.100.142:80>
        ServerAdmin serveradmin@bbgi.com
        DocumentRoot /home/drupal_1
        ServerName mysite.com
        ServerAlias www.mysite.com
        Alias /movies /home/movies/
        ErrorLog /var/log/httpd/mysite.com_err_log
        CustomLog /var/log/httpd/mysite.com_log special
    
        # Rewrite Rules #####################
        RewriteEngine On
        RewriteRule ^/webmedia/(.*) / [R=301,L]
        # end Rewrite Rules #################   
    </VirtualHost>
    
    0 讨论(0)
提交回复
热议问题