Viktor
Viktor

Reputation: 547

Htaccess Rewrite Rule with index.php exception

We have a website that redirects based on the URL string

Allow from all
RewriteEngine on
RewriteRule ^(.*)$ redir.php?j=$1 [R=301,L]

Where redir.php is an actual URL. This htaccess file works great, however, I'd like to make an exception for index.php or the root URL. How can we modify the above htaccess to add the exception without disturbing the existing functionality?

Similar question: htaccess Rewrite path to subdomain except the Index Document - however we don't want to have a subdomain. This is the root domain. I know we need a rewriteCond statement but we don't want to disturb the existing functionality.

Upvotes: 1

Views: 170

Answers (1)

Rajat Gupta
Rajat Gupta

Reputation: 26

You can try following redirect rule.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ redir.php?j=$1 [R=301,L]

Upvotes: 1

Related Questions