0

I'm using following htaccess rule which is proposed all over internet for removing index.php in codeigniter urls. And there are some of the redirection rules i added above it.

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L] 

The problem is: I'm getting some odd http request, which i think is caused by htaccess rules above. Here are some of them :

https://www.sitename.com/index.php/favicon.ico which ought to be .com/favicon.ico

https://www.sitename.com/index.php/scripts/jquery.js which ought to be .com/public/jquery.js as a side note im using base tag to redirect assets to /public/

strange thing is i couldnt find where the second redirection happens i tested whole site and javascript & css files load correctly

i handled this redirections by making my controller ignore those requests but a while ago a strange error happened. which i asked here: https://stackoverflow.com/questions/11775849/htaccess-didnt-work-until-renaming-and-then-renaming-back

my guess is that, even though i ignore misredirected request, hosting company receives them and probably it was causing some trouble for them which led to the problem i shared in linked question by a maintenance of hosting company.

Anyway, Question is: How can i make htaccess rule only redirect requests that doesnt have file extension at the end?

1 Answer 1

1

You're missing a line before the REQUEST_FILENAME line:

 RewriteCond $1 !^(index\.php|assets|something|fav\.ico|robots\.txt)

You can modify this to suit your needs. I've got my JS/CSS etc in the assets folder so it's not affected by the rewrite.

so the full .htaccess will look like this:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond $1 !^(index\.php|assets|something|fav\.ico|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L] 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.