Redirect * .php to clear url

My htaccess is not working:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\.php$ /blah/$1 [R=301,L] RewriteRule ^(.*)$ /blah/index.php/$1 [L] 

Basically /blah/about.php should be redirected to / blah / about

I use codeigniter, so the last line is required to handle the urls.

Redirecting works fine, but I get an internal server error in / blah / about

** Edit - error log:

The request exceeded the limit of 10 internal redirects due to a probable configuration error. Use "LimitInternalRecursion" to increase the limit, if necessary. Use the "LogLevel debug" to get the backtrace.

+3
source share
4 answers

Thanks @Cryo for the help, this fix:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\.php$ /blah/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /blah/index.php/$1 [L] 
+1
source

I think you just need to change your last line:

 RewriteRule ^(.*)$ /blah/index.php?/$1 [L] 

I do not have much experience with CodeIgniter, but in general, the framework wants to push all requests through the central controller (index.php), and then parse the request URL inside.

EDIT: just updated my answer with an example from here: http://codeigniter.com/wiki/mod_rewrite/ , this should be the way CodeIgniter wants it.

UPDATE: you should probably duplicate RewriteConds for the second RewriteRule, they only apply to the first:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\.php$ /blah/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /blah/index.php/$1 [L] 
+2
source

What about:

 RewriteRule ^(.*)(\.php)?$ /blah/index.php/$1 [L] 

and delete the previous line.

Also make sure /blah/about.php does not exist.

0
source
 Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\$ $1.php [NC] 
-1
source

All Articles