简体   繁体   中英

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

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-.... ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM