deepu sankar
deepu sankar

Reputation: 4455

Rewrite url using .htaccess file

I want to add https in a specified url

 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteCond %{HTTP_HOST} ^magsonwink.winkplatform.com/Shopping/paynow
 RewriteRule ^(.*)$ https://magsonwink.winkplatform.com/Shopping/paynow%{REQUEST_URI} [QSA,R=301,L]  

but this not worked for me. After googling i can't get a specified answer. if any one know about this please help me

Thanks in advance.

Upvotes: 0

Views: 21

Answers (2)

anubhava
anubhava

Reputation: 785146

Here is the corrected code:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} ^magsonwink\.winkplatform\.com$ [NC]
RewriteRule ^Shopping/paynow(?:/.*|)$ http%1://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]  
  • Above code will work both with HTTP and HTTPS
  • No need to use QSA flag since you aren't modifying query string

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143886

The %{HTTP_HOST} variable is only the hostname, no URL-path info is in it. So you need to remove it and add it to the pattern in your rule:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^magsonwink.winkplatform.com$ [NC]
RewriteRule ^/?Shopping/paynow(.*)$ https://magsonwink.winkplatform.com/Shopping/paynow$1 [QSA,R=301,L]  

Upvotes: 0

Related Questions