Url rewriting in vhost add a slash /

Discussion in 'Installation/Configuration' started by GarGamel55, Dec 5, 2011.

  1. GarGamel55

    GarGamel55 New Member

    Hi,

    In my .htaccess i've this rule :
    Code:
    RewriteRule ^(.*)\.html$ /?page=$1 [R,L]
    it works very well : website.com/test.html returns website.com/?page=test

    But if I put directly in my vhost (since panel websites/options/Directives Apache), i've an error :
    Code:
    RewriteRule ^(.*)\.html$ /?page=$1 [R,L]
    website.com/test.html returns website/?page=/test instead of website.com/?page=test

    Why a "/" is added? :confused:

    Thanks
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The redirect function is made to redirect a domain to a directory and not to a single file. For that reason it adds a / at the end if no / is added.

    For the rewrite rule that you posted above, create a file named .htaccess in the web directory and add the rule there.
     
  3. GarGamel55

    GarGamel55 New Member

    I already have one .htaccess file with a lot of rules in the directory /web.

    I want to put all the rules directly into the vhost to ensure that the file is not loaded on every page visited. (I have over 5,000,000 page views per month)

    So it is not possible?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Sure, just add them in the apache directives field.
     
  5. GarGamel55

    GarGamel55 New Member

    This is what I do since the beginning and what I always slash which is added
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    The rewrite rules that you enter in the apache directives field are not altered by ispconfig. You can check that in the vhost file.
     
  7. GarGamel55

    GarGamel55 New Member

    I am looking for several days, but i've no idea

    My vhost apache2
    Code:
    <Directory /var/www/website.com>
        AllowOverride None
        Order Deny,Allow
        Deny from all
    </Directory>
    
    <VirtualHost *:82>
          DocumentRoot /var/www/website.com/web
    
        ServerName website.com
        ServerAlias www.website.com
        ServerAdmin [email protected]
    
        ErrorLog /var/log/ispconfig/httpd/website.com/error.log
    
    
        ErrorDocument 400 /error/400.html
        ErrorDocument 401 /error/401.html
        ErrorDocument 403 /error/403.html
        ErrorDocument 404 /error/404.html
        ErrorDocument 405 /error/405.html
        ErrorDocument 500 /error/500.html
        ErrorDocument 502 /error/502.html
        ErrorDocument 503 /error/503.html
    
        <IfModule mod_ssl.c>
        </IfModule>
        <Directory /var/www/website.com/web>
            Options FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
        <Directory /var/www/clients/client0/web2/web>
            Options FollowSymLinks
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    
        # Clear PHP settings of this website
        <FilesMatch "\.ph(p3?|tml)$">
            SetHandler None
        </FilesMatch>
        # php as fast-cgi enabled
            # For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
        <IfModule mod_fcgid.c>
            IdleTimeout 300
            ProcessLifeTime 3600
            # MaxProcessCount 1000
            DefaultMinClassProcessCount 0
            DefaultMaxClassProcessCount 100
            IPCConnectTimeout 3
            IPCCommTimeout 360
            BusyTimeout 300
        </IfModule> 
    	
    	<Directory /var/www/clients/client0/web2/web>
            AddHandler fcgid-script .php .php3 .php4 .php5
            FCGIWrapper /var/www/php-fcgi-scripts/web2/.php-fcgi-starter .php
            Options +ExecCGI
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^website.com$ [NC]
        RewriteRule ^(.*)$ http://www.website.com$1 [R=301,L]
    
        # add support for apache mpm_itk
        <IfModule mpm_itk_module>
          AssignUserId web2 client0
        </IfModule>
    
        <IfModule mod_dav_fs.c>
              # Do not execute PHP files in webdav directory
          <Directory /var/www/clients/client0/web2/webdav>
                <FilesMatch "\.ph(p3?|tml)$">
              SetHandler None
            </FilesMatch>
          </Directory>
          # DO NOT REMOVE THE COMMENTS!
          # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
          # WEBDAV BEGIN
          # WEBDAV END
        </IfModule>
    
    RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ (/.*)?/index.(htm|html|php|asp)
    RewriteRule ^(.*)index.(htm|html|php|asp)$ /$1 [R=301,L]
    
    RewriteRule ^(.*)\.html$ /?page=$1 [R,L]
    </VirtualHost>

    My nginx vhost (for statics)

    Code:
    server {
            server_name www.website.com;
    
            location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf|mp3)$ {
            #replace $host by domain without www.
            root   /var/www/www/website.com/web;
            expires       7d;
            access_log     off;
            }
    
            location / {
            proxy_pass http://127.0.0.1:82;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            access_log off;
            }
    }
    
     

Share This Page