Reputation: 1451
I want to redirect a page to index.php. When I click on a link , it redirects to something like http://example.com/article.php
which doesn't exist yet. As it doesn't exist, I want to redirect to index.php.
I tried something like :
RewriteRule ^article.\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [R=301]
This code redirect to index.php but with every link on the site and not only with article.php
Upvotes: 2
Views: 418
Reputation: 784878
You can use this rule instead:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?:^|/)article\.php$ /index.php? [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
ensures that redirect only happens if index.php
is not a valid file in your system.
Upvotes: 1