codingtcher.com
Theme Night
Home
Login

Htaccess if condition rewriterule

Home » Tutorial Post » Htaccess if condition rewriterule

Example


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^user/login(?:\/([^/]+))?$ file.php?name=$1 [L]
RewriteRule ^login(?:\/([0-9]+))?$ file.php?id=$1 [L]

Another Example


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(?:([a-zA-Z0-9]+))?(?:\/([0-9]+))?$ file.php?name=$1&id=$2 [L]
RewriteRule ^(?:([a-zA-Z0-9]+))?(?:\/([0-9]+))?$ file.php?name=$1&id=$2&action=category [L]

Related Post