TheLittleHenry
TheLittleHenry

Reputation: 33

http to https redirect htaccess not working

I found a lot of similar answers but so far I could not manage the right thing that I want. It seems very easy or maybe somebody already answered but for me it's not working anymore..

So at the end I want https://example.com/product/624567

In my htaccess file I have already a rule something like this

RewriteEngine On
RewriteRule ^([a-z0-9-]{1,40})/([0-9]{1,12})$ fixMe.php?request=$2 [L]

Now if someone calls a URL following the above mentioned pattern with or without https all time it should redirect to the desired url(https://example.com/product/624567). To achieve this redirect I set another rule something like

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} product
RewriteRule ^product/([0-9]{1,12})$ https://%{HTTP_HOST}/product/$1 [L,R=301,NE]

But I am always getting a 404 error!! Could anyone please help me what i am doing wrong. Thanks

Upvotes: 1

Views: 49

Answers (1)

Croises
Croises

Reputation: 18671

Try with:

RewriteCond %{HTTPS} off
RewriteRule ^product/[0-9]{1,12}$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,NE,L,R=301] 

But just place the lines after RewriteEngine On and before RewriteRule ^([a-z0-....;

Upvotes: 2

Related Questions