Warwick Warwick - 3 months ago 31
Apache Configuration Question

Correct syntax for mod_rewrite?

What is the correct syntax to use in an Apache 2.4.7

.htaccess
file to get

http://www.example.com/go/stuff


to rewrite to:

http://www.example.com/index.php?tab=go&page=stuff
?

What syntax do I use in the
RewriteCond
and
RewriteRule
directives?

Answer

You can try this rule in site root .htaccess:

RewriteEngine On

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?tab=$1&page=$1 [L,QSA]