Reputation: 2879
I am using .htaccess to create seo friendly url and also to redirect my HTTP request to HTTPS
When i don't use HTTP to HTTPS rule, my url reads i.e. http://www.domain.com and when some one clicks username the url changes to http://www.domain.com/username
But when i use HTTP to HTTPS rule, it interferes with the url when i click username i.e. https://www.domain.com and when some one clicks username the url changes to https://www.domain.com/username?d=username
I would want it when i use the HTTP to HTTPS rule, and i click the username my urls to look like i.e. https://www.domain.com and when some one clicks username the url changes to https://www.domain.com/username
the problem is the https://www.domain.com/username?d=username url
Here is my .htaccess code
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?d=$1
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 0
Views: 741
Reputation: 24478
Put your redirects first and use L flags. Also you can consolidate the rules if you use your domain name.
RewriteEngine On
#redirect to https and/or www/https
RewriteCond %{HTTP_HOST} ^domain\.com [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?d=$1 [L]
Upvotes: 4