简体   繁体   中英

non www to www for both http and https not working

Have searched and applied many of the rewrite rules available but no avail,

I am trying

http://website.io/paypal should go http://www.website.io/paypal but it simply goes to www home page http://www.website.io

should be the same for https. Or at lest non-www redirects to https://www.website.io/paypal is fine, but should carry the page name.

after many trial and error versions here is the closest one I have got which isn't working good

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# WordPress Defaults
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

UPDATE

It seems nothing wrong with redirection though, www and non www domains were mapped to different ips thus not found on non-www urls.

Here is your exact working code. This will redirect you to your desired page perfectly.

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI}paypal [R=301,L]

# WordPress Defaults
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Note: Only this below line has some minor change otherwise you have done great job.

RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI}paypal [R=301,L]

Let me know if it solves your issue ?

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