Canonical URL's for Magento: Currently website has multiple url for one page.
Need to redirect below given url using 301 redirection, example:
http://www.example.com/index.php/
http://www.example.com/
http://example.com/index.php/
http://example.com/
to
http://www.example.com/
Need it for SEO purpose, Otherwise Search Engine is treating each page as duplicate.
Please follow the steps
http://www.example.com/ in system->configuration->General -> Web -> unsecure and secure
Enable search Engine optimization in System -> Configuration -> Web -> Search Engines Optimizations, select YES
Now, add below code in .htaccess file to remove index.php from url
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
Now add below code in .htaccess file to always redirect to http://www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Thanks
You can follow following steps
Enable apache mode_rewrite
http://www.example.com/ in system->configuration->General -> Web -> unsecure and secure
Enable search Engine optimization in System -> Configuration -> Web -> Search Engines Optimizations, select YES
check if RewriteBase / in .htaccess. if DOCUMENT_ROOT is another directory than RewriteBase /MAGENTO_DIR/
Alternatively, you can also redirect to virtual host
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
This apache redirect from non www to www might be helpful for you
Related
I want to redirect an old domain (https & www) to the main one. I need to redirect it to the home page and blog. But, there are 4 pages on the old site I want to redirect to the subdomain of the main page.
How it should look:
Oldwebsite1.com -> mainwebsite2.com
Oldwebsite1.com/blog -> Mainwebsite2.com/blog
Oldwebsite1.com/category1 -> new.mainwebsite2.com/category1
Oldwebsite1.com/category2 -> new.mainwebsite2.com/category2 /// etc...
Will typical code like this work or do I need to adjust it?
#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.mainwebsite2.com/$1 [R=301,L]
Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs. These also handles optional www in your host name too.
RewriteEngine ON
##For Oldwebsite1.com -> mainwebsite2.com
RewriteCond %{HTTP_HOST} ^(?:www\.)Oldwebsite1\.com$ [NC]
RewriteRule ^/?$ http://mainwebsite2.com [R=301,L]
##For Oldwebsite1.com/blog -> Mainwebsite2.com/blog
RewriteCond %{HTTP_HOST} ^(?:www\.)Oldwebsite1\.com$ [NC]
RewriteRule ^(blog)/?$ http://mainwebsite2.com/$1 [NC,R=301,L]
##For Oldwebsite1.com/category1 -> new.mainwebsite2.com/category1 OR Oldwebsite1.com/category2 -> new.mainwebsite2.com/category2
RewriteCond %{HTTP_HOST} ^(?:www\.)Oldwebsite1\.com$ [NC]
RewriteRule ^(category1|category2)/?$ http://new.mainwebsite2.com/$1 [NC,R=301,L]
I have follwing htaccess for redirecting to www, https and index.html to /:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.html$ / [NC,R,L]
On the website I use a wordpress blog on /blog, which gives this error if I try to access it:
ERR_TOO_MANY_REDIRECTS
I can fix this by swaping the rule order, first comes redirect to www and then https, but then the redirect to www does not work
Okay I found the issue. As a programmer you really should check from time to time what people who have some access to site settings are doing.
In the wordpress login for the admin in settings -> general a custom domain was entered which was https://example.com/blog etc. which means wordpress blog redirected back to the version without www.
The fix is to add www to the wordpress setting.
Force "https" and "www" redirect
I am trying to see if there is a way to redirect url to https://www.example.com
For example, if people are entering the url http://example.com/subfolder, then it should redirect to https://www.example.com/subfolder.
This is a Wordpress website. If I go to Settings => General => I see WordPress Address(URL) and Site Address (URL) are grayed out so I can't enter any url. Both shows as http://example.com
I went to phpMyAdmin=> option table to change the WordPress Address (URL) and Site Address (URL) to https://www.example.com but I still see the http://example.com on my wordpress general setting panel.
I looked at the wp-config file and found the following code that appears to be preventing me from entering custom url.
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
It seems like the WordPress Address(URL) and Site Address(URL) are enforced by the codes here.
My hosting provider recommanded using htaccess to enforce the ssl by putting the code below:
#Force SSL on entire site
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/$1 [R,L]
But this guide doesn't really tell us how to enforce www as well.
I found another guide here .htaccess - how to force "www." in a generic way? that explains how to enforce domain.com to www.domain.com. This one supposedly also check https and implement to the rewrite rule.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Now, someone else is recommanding the following code below, claiming that the first one above will only work if you want all sub-domains forwarded to www.yourdomain.com. I am just confused which one I need to choose?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I am trying to see which option would be the best solution to implement the force redirect? Or should I get rid of those four define() codes from wp-config file so I can setup redirect with wordpress general setting?
is it possible with .htaccess to mask a redirect of host to subdomain.
So that example.co.uk is masked to subdomain.test.co.uk, but still appears in browser as example.co.uk
I have tried using
RewriteCond %{HTTP_HOST} example\.co\.uk [NC]
RewriteRule ^(.*)$ http://subdomain.test.co.uk/$1 [NC,L]
But that just the redirect host to subdomain.test.co.uk, which isn't what I want.
Tried using [r=301] as one of the params too.
I have very limited access to hosting and it doesn't allow add-on domains (currently using parked domains to get host in .htaccess). If there is another solution I'm all ears :)
UPDATE
Tried changing the .htaccess to :
Options +FollowSymLinks -MultiViews
ProxyRequests On
ProxyPreserveHost On
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} simplysleeptime\.co\.uk
RewriteRule ^(.*)$ http://simplysleeptime.labithiotis.co.uk/$1 [NC,P]
RewriteCond %{HTTP_HOST} zurvivor\.co\.uk [NC]
RewriteRule ^(.*)$ http://zurvivor.labithiotis.co.uk/$1 [NC,P]
but i can't edit the httpd.conf to enable mod_proxy as I don't have full access to godaddy hosting.
I have a domain staticbackup.mydomain.com which has a static backup of the main site incase of server failure I can quickly switch the www. cname to point to staticbackup.mydomain.com (A record)
On the staticbackup I don't want the site accessible if you visit via statisbackup.mydomain.com, only if it's www.mydomain.com
Is there a way I can do this with htaccess?
This is what I have created (the site is live and I cannot test)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^staticbackup.mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/ [r=301,nc]
I would recommend you deny access to that domain:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^staticbackup.mydomain.com [NC]
RewriteRule .* - [F]