Magento non www to www - .htaccess

I am pulling my hair out here.
I have created a landing page which is http://www.pps-supplements.com/samples
it works and you can access it fine - no problems.
If you type in the address bar:
pps-supplements.com/samples
it takes you to the home page which is not good and causing me to have a headache.
My website is working well for non www to www on home page and categories but not on cms pages.
I have read a few posts on here and tried their solutions which is to edit the htaccess file but it hasn't fixed it.
Does anyone have any ideas how I can resolve this issue??
Pretty please!

You could try this in your .htaccess file....
Be sure to add it above any other rewrite rules or conditions you may already have in your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.pps-supplements\.com [NC]
Rewriterule (.*) http://www.pps-supplements.com/$1 [R=301]
</IfModule>
This will redirect any domain that is not www.pps-supplements.com to the version with www's
Also very handy for using when pointing multiple domains at a site.
Also, be sure that the webserver is set-up to receive the non www version, as in that it is listening for that version, as well as for the version with www's.

For anyone else looking at the accepted answer and running into issues with it not working you may have other Rewrites in place that need to be stopped from executing.
You can stop further execution by including the "L" param.
Example:
Rewritecond %{HTTP_HOST} !^www\.domain\.com [NC]
Rewriterule (.*) http://www.domain.com/$1 [R=301,L]

I wanted to redirect from example.com/category/ to www.example.com/category/
and I found solutions:
turn off Auto-redirect to Base URL in backend
and use this code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>

For Magento Multistore-Setups:
Rewritecond %{HTTP_HOST} ^example\.com [NC]
Rewriterule (.*) http://www.example.com/$1 [R=301,L]

Related

Internal Redirect blog/article.php?id=1 to blog/article/1

I have a blog folder in the public_html folder on my server with godaddy.
The .htaccess (in public_html) :
RewriteEngine on
Options +FollowSymlinks -Multiviews -Indexes
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} /blog/article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ blog/article/%1? [R=302,L]
RewriteRule ^blog/article/([^/.]+)/?$ /blog/article.php?id=$1 [L,QSA,NC]
The page takes me to 404 page on my online host with godaddy but it works fine on localhost.
I also tried:
RewriteCond %{QUERY_STRING} (^|&)article\.php\?id=(.*)(&|$)
RewriteRule ^(.*)/article.php$ $1/article/%1? [NC,L]
but that didn't do anything.
Please help!
Figured it out. For anyone that might run into the same problem, here is the simple solution:
Make sure that your tag contains the real url.
What I did was, I put the custom url in the tag and godaddy was not recognizing it.
So what I did was
article 1
instead it should be
article 1
That way it will redirect to the custom url correctly.
Hope that helps!

Domain redirection with folder separation. htaccess

After redirecting my client domain to my server i created rewrite rule in root folder .htaccess file to point domain to a subfolder1 (joomla website):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subfolder/
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Everything worked fine but today i found out that i can access any other subfolder in my server by entering for example: myclientdomain.com/subfolder2 and what's worse google can index that and show it in search results.
If there is any way to redirect a domain in a way that I won't be able to access any other folder on my server?
I would really appreciate help as I searched throughout google for answer, my server tech support said that they don't really support these kind of problems (they only gave me a piece of code from above) and I don't really know anything about .htaccess rules and how it works.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder\/?(.*)?$
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Change above rule to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
# if current URI is not starting with /subfolder/ then route to /subfolder/
RewriteRule ^((?!subfolder1/).*)$ subfolder1/$1 [L,NC]

how to redirect www.sub.domain.com to sub.domain.com?

how to redirect www.sub.domain.com to sub.domain.com?
other info:
right now sub.domain.com works, www.sub.domain.com is 'server not
found'.
im using drupal 6. I dont want to add an A record because the caching module i use (Boost) will cache a version of the site with www and without www, effectively doubling the cache size. <-- Not really sure about that but that's the case with my site at its previous host. In any case this is probably just a simple htaccess issue.
Doesn't this helps, inside .htaccess file?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
Also: https://drupal.stackexchange.com/questions/50552/how-to-keep-domain-consistency-with-or-without-www/50553#50553

.htaccess RewriteRule issue

I have a domain at OVH that links to my EC2 instance like this:
www.mysite.com --> 12.34.56.78/folder/
So everytime I type "www.mysite.com" in my address bar I end up on my website but the URL has been replaced to "12.34.56.78/folder/".
I'm currently trying to tweak a .htaccess file at the root of my server but it doesn't seem to work...
Here is the content of the file:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/ [L]
Maybe I'm not looking at the right solution... Anyway if you can help me, I'll be grateful!
Cheers,
You are missing a couple of things that I added below
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
#$1 will include the original URI in the redirect, 301 for permanent
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

How do I redirect one subdomain to another, when they both point to the exact same files?

I have a site that has two domains pointing to it, let's call them:
work.mysite.com
play.mysite.com
This is bad practice, so I want to choose work.mysite.com and make it the canonical URL, permanently redirecting play.mysite.com to it.
I'm in the root directory for these two domains, in a .htaccess file, banging my head against the cement floor and wishing I wasn't here. Here's what I am currently trying. Tell me how totally wrong I am, please?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?play\.mysite\.com [NC]
RewriteRule ^/?(.*)?$ http://work.mysite.com/$1 [R=301]
</IfModule>
That gets me a really pretty 500 Internal Server Error. How far off am I?
RewriteCond %{HTTP_HOST} !work.example.com [NC]
RewriteRule ^(.*)$ http://work.example.com/$1 [R=301,L,QSA]
This will also remove the www from www.work.example.com
Not sure if the QSA is needed, but I think it will prevent play.example.com/?home from being redirecting to work.example.com/ instead of work.example.com/?home
Ah, I think I was just trying to be too fancy. This seems to work fine:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^play.mysite.com$
RewriteRule ^(.*)$ http://work.mysite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.play.mysite.com$
RewriteRule ^(.*)$ http://work.mysite.com/$1 [R=301,L]
</IfModule>
This worked for me.
RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com
RewriteRule (.*)$ http://uieiq.webcodehelpers.com/$1 [R=301,L]
I used this to redirect a subdomain to another subdomain.

Resources