1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Move rewrite rules from .htaccess to virtual host conf

Discussion in 'Server Configuration and Hosting' started by sinucello, Jun 27, 2014.

  1. sinucello

    sinucello Well-Known Member

    I`d like to move my rewrite rules from the .htaccess file in the XF document root to the virtual host configuration. If I just copy them, they don`t work. Can anybody tell me what I`d have to change to make it work? Here`s the content of my .htaccess:
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} -f [OR]
      RewriteCond %{REQUEST_FILENAME} -l [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^.*$ - [NC,L]
      RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
      RewriteRule ^forum/(.*)$ /$1 [R=301,NC,L]
      RewriteRule [^/]+/([\d]+)-.+-([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
      RewriteRule [^/]+/([\d]+)-.+.html showthread.php?t=$1 [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    thank you - all the best,
  2. caliman

    caliman Active Member

    Do you have root access on your server? I think what you want is a .conf file in /etc/httpd/conf.d
  3. sinucello

    sinucello Well-Known Member

    Yes, I have root access and in my apache configuration there are different virtual hosts. The configuration files of the virtual hosts are stored in /etc/apache2/sites-available/name_of_host. The virt.. host conf for my forum looks like this:

            ServerName myforum.de
            Redirect 301 / http://www.myforum.de/
            ServerName www.myforum.de
            DocumentRoot /var/www/vhosts/www.myforum.de/httpdocs
            php_admin_flag safe_mode Off
            ServerAlias                 myforum.com
            DirectoryIndex          index.html index.htm index.php
            ErrorDocument 401 default
            ErrorDocument 403 default
            ErrorDocument 404 default
            ErrorDocument 500 default
            RewriteEngine On
            RewriteMap lowercase int:tolower
            RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^myforum\.de$
            RewriteRule .* http://www.myforum.de%{REQUEST_URI} [R=301,L,NE]
            RewriteCond ${lowercase:%{HTTP_HOST}|NONE} ^(www\.)?myforum\.com$
            RewriteRule /(.*) http://www.myforum.de/$1 [R=301,L,NE]
            <Directory "/var/www/vhosts/www.myforum.de/httpdocs">
              #RewriteEngine On
              #RewriteCond %{REQUEST_FILENAME} -f [OR]
              #RewriteCond %{REQUEST_FILENAME} -l [OR]
              #RewriteCond %{REQUEST_FILENAME} -d
              #RewriteRule ^.*$ - [NC,L]
              #RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    I want to transfer the rewrite rules from the .htaccess file to this virtual host configuration but copy them 1:1 doesn`t work. It seems that the environment variables or path info is different in the .htaccess file.
  4. Renegade

    Renegade Well-Known Member

    You have to put these in the directory tags and mention the full path to the xenforo directory.

    <Directory "/var/www/path/to/your/web/dir">
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

Share This Page