Not able to redirect

Hi,

I am changing the PHP extetsions to HTML, HTM extentions with Rewrite mod and each to index.php. below is the code for it.

DirectoryIndex index.php

RewriteEngine On

RewriteBase /foldername


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^/index.php

RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]

RewriteRule (.*) index.php [L]

It is working fine however i am facing one problem. If i open the URL as http://mysite.com/index.php it is showing “index.php” i would like to redirect to “index.html” however it is not working. i am putting below codes

Redirect 301 ^/index.php$ http://mysite.com/foldername/index.html

AND

RewriteRule ^/?index\\.php$ index.html [R=301,L]

It is not working. it is giving me Redirect Loop. I understand that why it is giving me Redirect Loop but somehow i am not been able to find the exact code for this. Can anyone help me please.

Thanks

viv,

Of course there is a loop! You are sending all {anything}.html to index.php then redirecting to index.html to index.php to … well, you get the idea.

what you should to (to redirect to index.html is change the index.php exclusion to index.html and the RewriteRule’s redirection to index.html, too.

Regards,

DK

Thankyou DK, However, it is a bit confusing…:shifty:

Thanks

viv,

RewriteEngine On
RewriteBase /foldername
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.[COLOR="Red"]html[/COLOR]
RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.[COLOR="Red"]html[/COLOR] [L]

Regards,

DK

DK,

I have changed my code to DirectoryIndex index.php

RewriteEngine On

RewriteBase /foldername

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^/index.html

RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]

RewriteRule (.*) index.html[L]

It is still not working. This code is giving me page not found error page.

Let me give you more info. the site is in php and i want to direct all the pages html, htm to index.php which is working fine.

problem with this is if i put like mysite.com/index.php then it does NOT redirect to mysite.com/index.html which i am trying to do however it is giving me redirect loop that is understandble. pls help me out.

Sorry for delayed come back here as i had to leave due to some person issues.

Thanks
Viv

Viv,

Two things:

  1. Are you still using the Redirect from the first post? If so, remove it, please, as it will take precedence over mod_rewrite.

  2. I have a major problem with using RewriteBase as it’s intended to “undo” a mod_alias redirect. Personally, I’d remove the RewriteBase directive and move your .htaccess code to the foldername subdirectory (without the third and fourth RewriteCond statements). On the basis that this would then look exactly like a WordPress setup, I’d also recommend checking the configuration file to be sure it knows it’s in the foldername subdirectory.

If those don’t resolve your problem, please post a test URI for me to look at, too.

Regards,

DK

Thanks DK,

I have somehow done what i required but Not with Htaccess but with PHP. In any case i will try your these suggestions in HTACCESS and let us know and will post URI as well (if needed) to solve these kind of problems in future.

Thanks
Viv