Phillip Dews
Phillip Dews

Reputation: 51

remove my index.php file using .htaccess

I am trying to remove the trailing index.php on my main site using .htaccess file and the following code....

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(html?|php[45]?|[aj]spx?)\ HTTPS/
RewriteRule index\.(html?|php[45]?|[aj]spx?)$ https://www.gekkodev.com/%1 [R=301,L]

But of course it is still not working! I think the problem is my ssl certificate as that code has worked fine on lots of other sites

Any ideas would be greatly accepted! Many thanks.

Upvotes: 1

Views: 69

Answers (2)

Phillip Dews
Phillip Dews

Reputation: 51

Sorted this is how I have done it!

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule index\.(html?|php[45]?|[aj]spx?)$ https://www.gekkodev.com/%1 [R=301,L]

Cheers IMSoP

Upvotes: 0

IMSoP
IMSoP

Reputation: 97783

Your RewriteCond is taking entirely the wrong approach. An HTTPS request is just an HTTP request wrapped in SSL/TLS security - it will not contain the string HTTPS in the request line, which is what you are checking for.

If you want the rule only to apply to HTTPS requests, just use the %{HTTPS} variable, as listed in the documenation:

RewriteCond %{HTTPS} on

(I've seen a lot of rewrite rules testing %{THE_REQUEST} recently, and I'm not sure why, as it should really only be used as a last resort when nothing else can work.)

Upvotes: 3

Related Questions