Anirudh Poddar
Anirudh Poddar

Reputation: 11

htaccess rule for redirect on a page if requested url not found

Dynamic url created is not the same as name of the page

Example:

The page name remains same example - example.php but the dynamic requested url is example-acd.php.

How to redirect to a new page if the dynamic url not found on the server.

Using this code:

RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^.*$ /404.php [L]

It is working fine for the static url but not for the dynamic url

Upvotes: 1

Views: 660

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You need to use %{REQUEST_FILENAME} in place of %{REQUEST_URI}

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ /404.php [L]

Upvotes: 1

Related Questions