Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have configured a virtual host in my local machine and every thing is working fine. Now I want to use SEO friendly urls. To achieve this I have used the .htaccess file.

My virtual host configuration is:

<VirtualHost *:80>

    DocumentRoot "C:/xampp/htdocs/ypp"
    ServerName ypp.com
    ServerAlias www.ypp.com
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

and my .htaccess file has:

AllowOverride All
RewriteEngine On 
RewriteBase /ypp/ 
RewriteRule ^/browse$ /browse.php 
RewriteRule ^/browse/([a-z]+)$ /browse.php?cat=$1 
RewriteRule ^/browse/([a-z]+)/([a-z]+)$ /browse.php?cat=$1&subcat=$2 

The above .htaccess setting is not working. After that I modified my virtual host setting and it is working. The new virtual host setting is:

<VirtualHost *:80>

    RewriteEngine On
    RewriteRule ^/browse$ /browse.php
    RewriteRule ^/browse/([a-z]+)$ /browse.php?cat=$1
    RewriteRule ^/browse/([a-z]+)/([a-z]+)$ /browse.php?cat=$1&subcat=$2
    ServerAdmin postmaster@dummy-host2.localhost
        DocumentRoot "C:/xampp/htdocs/ypp"
    ServerName ypp.com
    ServerAlias www.ypp.com
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
    <Directory "C:/xampp/htdocs/ypp">
        AllowOverride All
    </Directory>
</VirtualHost>

Please let me know where I am going wrong in the .htacess file for url rewriting. I do not want to use the settings in virtual host, since for every change I have restart apache.

share|improve this question

migrated from stackoverflow.com May 15 '11 at 20:31

This question came from our site for professional and enthusiast programmers.

    
@parth: not a programming question. Voting to migrate to ServerFault. –  0xC0000022L May 15 '11 at 18:51
    
is it really AllowOverride All RewriteEngine On or AllowOverride All (new line) RewriteEngine On –  Daniel Ruf May 15 '11 at 18:59
    
Yep for every change you restart apache but this way apache will never have to check each time the htaccess when someone will read a page. Htaccess files in your case are far less efficient than htaccess. Think about that when going in prod. environment –  Olivier Pons Nov 20 '11 at 20:48
add comment

1 Answer 1

You must put AllowOverride All in your <Directory/> section of the server configuration.

The only Apache configuration files that can allow options are the ones directly in the server (main file, virtualhost, etc.).

The .htaccess file can only remove override rights.

That is:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/ypp"
    ServerName ypp.com
    ServerAlias www.ypp.com
    ##ErrorLog "logs/dummy-host2.localhost-error.log"
    ##CustomLog "logs/dummy-host2.localhost-access.log" combined
    <Directory "C:/xampp/htdocs/ypp">
        AllowOverride All
    </Directory>
</VirtualHost>

and the .htaccess file :

RewriteEngine On 
RewriteBase /ypp/ 
RewriteRule ^/browse$ /browse.php 
RewriteRule ^/browse/([a-z]+)$ /browse.php?cat=$1 
RewriteRule ^/browse/([a-z]+)/([a-z]+)$ /browse.php?cat=$1&subcat=$2 
share|improve this answer
1  
You are generally correct, except I believe mod_rewrite only requires AllowOverride FileInfo, so you should set it to that in the vhost config instead of All unless you really need to allow all directives in .htaccess. It's best to follow the principle of least privilege. –  Lèse majesté Dec 21 '11 at 7:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.