Search code examples
regex.htaccessmod-rewriteurl-rewritingfavicon

htaccess prohibits me from using full path


So i am just beginning to get my grasp around .htaccess and i have been able to prettify my URL's.

# localhost/index.php?side=kunder => localhost/kunder
RewriteRule ^([^\/\.]+)/?$ index.php?side=$1 [NC,L]

# localhost/index.php?side=kunde&id=1 => localhost/kunde/1
RewriteRule ^([^\/]*)?/([^\/]*)?$ index.php?side=$1&id=$2 [NC,L]

Problem is now i can't seem to navigate to my favicons which reside in root/favicons/favicon.ico

I guess it will treat is as follows: index.php?side=favicons&id=favicon.ico

Any help will be greatly appreciated!


Solution

  • You can use:

    # skip all files and directories from rewrite rules below
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    
    RewriteRule ^([^/]+)/?$ index.php?side=$1 [QSA,L]
    
    RewriteRule ^([^/]+)/([^/]+)/?$ index.php?side=$1&id=$2 [QSA,L]