Redirect in htaccess to real page

Viewed 41

What I have - URL like

http://example.com/index.php/anywords/anywords/anyname.php

or

http://example.com/index.php/anywords/anywords/

or

http://example.com/index.php/

What I want to have - redirect to

http://example.com/index.php

My current htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /(.*)/$
    RewriteRule ^ /%1 [R=302,L]
</IfModule>

Thanks

1 Answers

Generic solution for matching any words: Could you please try following. I have mentioned temporary redirect here, you could remove it if you don't want redirect on browser level.

RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/index\.php/([\w-]+/){1,}/[\w]+\.php/? [NC,OR]
RewriteCond %{REQUEST_URI} ^/index\.php/([\w-]+/){1,}/? [NC,OR]
RewriteCond %{REQUEST_URI} ^index\.php/?$ [NC]
RewriteRule ^(.*)$ /index.php [R=302,NC,L]


For specific words: Could you please try following.

RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/index\.php/anywords/anywords/anyname\.php/? [NC,OR]
RewriteCond %{REQUEST_URI} ^/index\.php/anywords/anywords/?$ [NC,OR]
RewriteCond %{REQUEST_URI} ^index\.php/?$ [NC]
RewriteRule ^(.*)$ /index.php [R=302,NC,L]
Related