how to add www in url in magento - magento

I am using magento 1.8.1 and I want to add www in our url.
e.g: now my url is like http://example.com/
I want like http://www.example.com/.
I search on google and got this solution:
rewriteCond %{HTTP_HOST} !^www.example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
referenced by
I dont know where to put this.

You need to follow below steps :
1 ) check in system >> configuration >> Web >> Unsecure and Secure check correct url are setup or not.
2) .htaccess changes :
RewriteCond %{HTTP_HOST} ^yoursitename.com$
RewriteRule (.*) http://www.yoursitename.com$1 [R=301]

The correct way to add the base url is in the system configuration, NOT rewrite rules in the .htaccess. First of all, make sure you have a CNAME record for www.example.com in your domain's zone file. Second, if you set http://www.example.com/ for your unsecure base url, and https://www.example.com/ for your secure base url, Magento will redirect to those urls during routing. For goodness sake, don't do any Magento redirection in your htaccess.
You can also set the redirect type code:

Related

Redirect subdomain to another laravel subdomain

I had a laravel project on a sub-domain and I migrated to another sub-domain.
I want to redirect all requests from old sub-domain to the new one.
For example:
https://old.website.com
https://old.website.com/login
https://old.website.com/contact
Should become:
https://new.website.com
https://new.website.com/login
https://new.website.com/contact
I moved all the files to another folder and added .htaccess with the following code:
RewriteEngine On
RewriteRule ^(.*)$ https://new.website.com/$1 [R=301,L]
But the issue is that public is added to the url for example:
https://old.website.com
Becomes:
https://new.website.com/public
So I get 404 not found error.
For the sub-domain I set the document root to point to public folder so no need to add the public directory to the url.
By the sounds of it, you likely have an internal rewrite to the /public subdirectory. Try the following instead:
RewriteRule ^ https://new.website.com%{REQUEST_URI} [R=301,L]
Test with 302 (temp) redirect first to avoid potential caching issues. You will need to clear your browser cache before testing.
I have this solution on one of my projects. To redirect requests from old sub-domain to the new one without the public folder in the URL, you could need to modify the .htaccess file. You can try the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.website.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old.website.com$
RewriteRule (.*)$ https://new.website.com/$1 [R=301,L]
This should redirect all requests to the new sub-domain while preserving the rest of the URL. This way, you should be able to access the pages at their new URL without encountering a 404 error.

Magento, redirect the url from "www.domain.com/home" to base url "www.domain.com"

I am trying to configure how to redirect my magento website from www.domain.com/home to base url www.domain.com, it always redirecting to www.domain.com/home
UPDATE
Thanks Amit, I use your solution
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/accueil
RewriteRule ^(.*)accueil$ http://www.cabas-durables.fr/$1 [R=301,L]
but I got error at the browser says
The page isn't redirecting properly
then I change the $1 after http://www.cabas-durables.fr/$1 to index.php, then it shows "http://www.cabas-durables.fr/index.php" at the browser, then I bring it back to $1 I got no error but it stays to "http://www.cabas-durables.fr/index.php"
I don't know where to change it to only "http://www.cabas-durables.fr/"
I will have problem with SEO if it not change
thanks
It can be better to use htaccess.
find
Options +FollowSymLinks
RewriteEngine on
Then
Put the below code in htaccess file
RewriteCond %{THE_REQUEST} ^.*/home
RewriteRule ^(.*)home$ http://www.domain.com/$1 [R=301,L]
Create URL Redirect in admin panel.
Use tagret path - "../"; it will redirect to the homepage.

Joomla live_site and mod_rewrite

I installed Joomla 2.5 in /joomla/.
It's accessible by http://www.example.com/joomla/.
But I want it to be accessible when I browse http://www.example.com/ (or example.com, without www)
I thought configuration $live_site is because of this, but change it to http://www.example.com/, and it showed a blank page.
Should I edit root directory .htaccess? or Joomla .htaccess file ?
Redirecting non-www version to www
You can Redirect your domain from "non-WWW" to "WWW".
To redirect your domain to "WWW" you need to define a rule in your ".htaccess" file.
You can upload this file in the "root" directory of your site
For that you can set a rule as follows :
*******************************************
RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
********************************************
After defining the above rule in your ".htaccess" file When you type your domain in URL domainname.com it will get
redirected to WWW.

Internal subdomain to folder redirect

I want to create folders on the fly, but make it seem like I am creating subdomains on the fly using mod_rewrite. e.g.
Create "john" folder using PHP
www.example.com/john/
Then be able to access whatever I put in there at:
john.example.com
Thank you in advance,
Kris
First you need to configure your server to accept any subdomain for your domain example.com and redirect it to your virtual host that as well has to accept any subdomain. After that, you can use the following rule to rewrite that subdomain internally to a folder with the same name:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ %1%{REQUEST_URI} [L]

Rewriting CNAME subdomain

I have a sub domain that I want to redirect to a different location using mod_rewrite. For example:
subdomain.example.com -> www.example.com/subdomain
I don't want to send a redirect to the browser though (so it doesn't know the page is different).
BTW subdomain.example.com has a CNAME record pointing to example.com.
Edit
Another example, just to clarify. It is very simple: If http://x.abc.com is entered in to the browser, Apache returns the contents of http://www.abc.com/x.
If both domains share the same directory, you could do this to rewrite the requests internal:
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule !^subdomain/ subdomain%{REQUEST_URI}
After the question has been clarified: This one works for me:
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteCond %1.%{THE_REQUEST} ^([^.]+)\.[A-Z]+\ (/[^\ ]*)
RewriteCond %{DOCUMENT_ROOT}$1 !-d
RewriteRule ^([^/]+)? %1%2
But you better go with what Brandon said.
In addition to what Gumbo stated above, you can use Apache's VirtualDocumentRoot statement to dynamically map URL to a dynamic location on disk. It allows you to use parts of the URL to build a path on disk. Check out this link for more information:
http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
Example:
URL = http://sub.example.com/dir/page.html
Server Path = /var/www/site.com/htdocs/sub/dir/page.html
VirtualDocumentRoot = /var/www/%-2.0.%-1.0/htdocs/%-3/
RewriteCond %{HTTP_HOST} ^([^.]+)\.abc\.com$
RewriteRule ^(.*)$ http://www.abc.com/%1$1 [R=301]

Resources