Search code examples
regexapache.htaccessmod-rewrite

RewriteRule based on multiple conditions


I can't seem to figure out how to get these conditions to happen with my .htaccess

http://example.com/index.php?page=about
to
http://example.com/about

and at the same time

http://example.com/index.php?process=login
to
http://example.com/p/login

I have tried to do this myself but I couldn't figure out how to do both at the same time.

Using Apache


Solution

  • put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    
    RewriteRule ^p/([^/]+)/?$ /index.php?process=$1 [L,QSA]
    
    RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]