For our shop CMS we have a system that works like this:
When a customer registers they will get a subdomain on our root domain.
Something like: myshop.daretoshop.nl
For SEO we want the users to be redirected to the non www version of this subdomain when they enter www.myshop.daretoshop.nl, so they are redirected (301) to myshop.daretoshop.nl
Is this possible with htaccess? We want this so happend with all subdomains, so maybe its possible to set this globally?
thanks in advance.
Use mod_rewrite.
For mod_rewrite directives to work using .htaccess, you need to set AllowOverride FileInfo. Details about how to configure mod_rewrite for your specific needs can be found in one of the similar questions, such as Generic htaccess redirect www to non-www.
You also need to configure your DNS server such that the subdomains are actually resolved to the IP address of your web server.
BTW there are absolutely no SEO benefits in redirecting http://www.example.com to http://example.com.
Related
I have two hosting accounts with different providers.
both sites have the following in the htaccess.
RedirectMatch 301 ^(.*).htm $1.html
On one site (a VPS) it works as expected and
//www.example.com/page.htm
is correctly forwarded to
//www.example.com/page.html
But on the other hosting provider (shared hosting. Different provider) it removes the www from the url so goes to:-
//example.com/page.html
It only strips the www if the htm-to-html redirect occurs. So it's not all pages that have the www removed so it's not a global setting removing www from all urls.
Is that redirect syntax wrong? If so then why does it only affect the domain on one hosting provider. Or is it a setting somewhere else in the website setup?
Thanks
RedirectMatch 301 ^(.*).htm $1.html
If you don't explicitly include the hostname in the target URL (ie. specify an absolute URL) then Apache gets this information from the current server. By default, this will be the hostname used in the request (www, non-www, or whatever). However, if the directive UseCanonicalName On is set, the hostname as defined by the ServerName directive will be used. This is what I guess is happening.
Unfortunately, on a shared server, you are not going to be able to change this behaviour. The UseCanonicalName directive can only be set in the server config, not .htaccess.
I think the only resolution is to be explicit and specify the canonical hostname in the above directive:
RedirectMatch 301 ^/(.+)\.htm$ http://www.example.com/$1.html
Some people recommended to always specify an absolute target URL for redirects to avoid such problems. (Personally, I would only do this out of necessity.)
I have domain registered in ovh. My site files are stored in folder called "www" in root directory. It was original ovh setup. A few days ago I discovered that i can use let's encrypt ssl certyficate. Now I have these addresses:
example.com,
www.example.com,
https://example.com,
https://www.example.com
I want to redirect:
example.com
www.example.com
https://www.example.com
to:
https://example.com
via .htaccess 301 redirection
I tried a lot of sample htaccess redirections from this and other sites. Non of them work perfectly for me.
For example redirection from example.com to https://example.com was ok, but from www.example.comtake me tohttps://www.example.com/wwworhttps://www.example.com with browser warning "unsafe content".
It is harder than i thought.
If you're using wordpress, you could install a simple pulgin called Really Simple SSl which will automatically do this redirection.
I'm stuck with htaccess redirect on this case:
I have myapp.com domain where my main website and service runs on. My customers logs into their accounts on myapp.com and use. Now, I am going to provide one of the features on a separate domain, let's assume "goto.com". However, I don't want to build a separate app on goto.com. I just want to redirect all coming requests to goto.com to a php script under myapp.com but this redirection should be in the backend (masked), not a 301 redirection.
Let me clear up:
myapp.com - /var/www/vhosts/myapp.com/httpdocs/index.php
goto.com --> masked redirection --> myapp.com/goto.php?$1
How can I do this with htaccess? Any suggestions?
Just found that it can be done with redirect [P] (proxy) method: RewriteRule ^(.*)$ http://myapp.com/public_view/$1 [P] What do you think? Is this a good and stable method?
That method is fine, it utilizes the mod_proxy module. The only thing I can suggest is adding the L flag as well in case you have other rules in your htaccess file.
A limitation with using the P flag in an htaccess file is that if a page or request to http://myapp.com/ redirects, then you're URL address bar will say http://myapp.com/ instead of your other domain. The only way around this is to use ProxyPassReverse but it doesn't work in an htaccess file. You'd need access to vhost config:
ProxyPass / http://myapp.com/public_view/
ProxyPassReverse / http://myapp.com/public_view/
Additionally, if http://myapp.com/ sets cookies, you'll need to use the ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath directives to rewrite those.
I have a domain, but it has no files on the webhost. I want to know if it's possible to do the following with only a .htaccess on my webhost.
But what I want to use this basically for is that I want to redirect my web root http://(www.)mydomain.net to http://domain2.net. And I want http://(www.)mydomain.com/1/ redirect to domain3.net.
Can anybody help me out?
Thanks a lot!
Use the htaccess Redirect line..
i think it would be this (i didn't check to verify it works... but fiddle with it):
Redirect http://mydomain.net http://domain2.net
Redirect http://mydomain.net/1 http://domain3.net
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
You can do this with s simple 301 directive mixed with directories:
I would point mydomain1.com to ip xxx.xxx.xxx.xxx/mydomain1 and then in the htaccess in that directory:
Redirect 301 / http://domain1.net/
Then you can repeat the same for site 2: point site to to ip xxx.xxx.xxx.xxx/mydomain2 and in the htaccess for that directory
Redirect 301 / http://domain2.net/
I've been searching the archives but I can't find anything that is making too much sense to me.
I have a site with a couple of subdomains which redirect to other sites.
E.g.
the visitor types - www.jmp.redtwenty.com.au - and is redirected to - http://creator.zoho.com/redtwenty/jmp-conversion-tracking
Is there any way to mask this redirect so that the visitor still sees jmp.redtwenty.com.au in the address bar?
I keep seeing mention of a rewrite rule in .htaccess but not sure if that is what I want.
Thanks
Mike
You can do this a few ways, but you'll need to make sure mod_proxy is enabled.
If you have control of the server config or the vhost config of the www.jmp.redtwenty.com.au/ domain, you can add this to it:
ProxyPass / http://creator.zoho.com/redtwenty/jmp-conversion-tracking/
Or in the htaccess file in the document root of http://www.jmp.redtwenty.com.au/:
RewriteEngine On
RewriteRule ^(.*)$ http://creator.zoho.com/redtwenty/jmp-conversion-tracking/$1 [L,P]