Question

I have my site in /srv/http/site-dir/, and in its root .htaccess with following:

Options -MultiViews

RewriteEngine On

Options -Indexes

RewriteBase /site-dir/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

It works that way, but now I would like to move those rules to httpd-vhosts.conf file, so what I need to change to have it working from there, and thus avoiding the use of .htaccess which I read is a bed practice if you have access to your main .conf file?

EDIT: entered this into my httpd-vhosts.conf to try as suggested but without success.

<VirtualHost *:80>
    DocumentRoot "/srv/http/site-dir"
    ServerName project-site-dir.my
    ServerAlias www.project-site-dir.my

    Options -MultiViews -Indexes

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^/site-dir/(.+)$ /site-dir/index.php?url=$1 [QSA,L]

    ErrorLog "/var/log/httpd/project-site-dir.my-error_log"
    CustomLog "/var/log/httpd/project-site-dir.my-access_log" common
</VirtualHost>
Was it helpful?

Solution

You can place this snippet in your httpd-vhosts.conf file:

<VirtualHost *:80>
    DocumentRoot "/srv/http/site-dir"
    ServerName project-site-dir.my
    ServerAlias www.project-site-dir.my

    Options -MultiViews -Indexes

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^/(.+)$ /index.php?url=$1 [QSA,L]

    ErrorLog "/var/log/httpd/project-site-dir.my-error_log"
    CustomLog "/var/log/httpd/project-site-dir.my-access_log" common
</VirtualHost>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top