A client of mine has found out today that someone has set up a spoof domain (1 letter different - design instead of designs) and has tried to set up credit accounts in his name.
The domain will undoubtedly be removed, but is it possible in the meantime using some htaccess trick to check if a visitor to www.designs.com has been referred from www.design.com and if they have, send them to a warning page?
You can use this code in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http(s)?://([^\.]+\.)?design\.com
RewriteRule ^.* /warning.html [L,R=302]
It will redirect any pages coming from design.com and its possible subdomains (using http or https) to a page named warning.html at the root of your project.
You can test this rule with this online tool.
Related
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
Google Analytics is showing my own root domain is the referral for a large portion of my website's traffic.
So, mywebsite.com is showing as the referrer for www.mywebsite.com.
I have tried adding a referral exclusion within Analytics with no success. I have cleaned my .htaccess which also hasn't been successful
.htaccess code
RewriteEngine On
Options +FollowSymLinks
# Redirects mywebsite/uk/anypage to mywebsite.eu/anypage
RewriteRule ^uk/(.*)$ /$1 [NC,R=302,NE,L]
# Redirect 404 to index
ErrorDocument 404 /
# Use www version
RewriteCond %{HTTP_HOST} ^mywebsite.eu [NC]
RewriteRule ^(.*)$ http://www.mywebsite.eu/$1 [L,R=301,NC]
This is what it looks like in Analytics:
I've put a lot of time into trying to find the cause so any suggestions, .htaccess related or otherwise, are very welcome
Did you migrate recently to Universal Analytics? It migrates the previous utmz cookie values that stored traffic source, so if your users had self-referrals prior to upgrading to UA, this will persist int your data. Could you check if there are new sessions in this traffic?
Make sure to add to the referral exclusion list your domain with and without the www.
For some reason certain sites it likes to have it while on others it does not, I would definitely try this and then see if the future sessions are any more clean before changing too much with the .htaccess.
I am a novice with server side coding so bear with me if the answer is obvious to some:
I designed the front end of a website sometime ago. It resides in a shared hosting environment as a subdirectory. I am trying to upload an .htaccess file in order to redirect to its mobile version ( that I did not design and that is hosted on another account). I have tried uploading the .htaccess file to both the root directory and the subdirectory and each have their issues.
When I upload to the root the redirect does not occur on any devices. It was not my wish but I was expecting that all websites under the root would be redirected to the mobile version of this one site but nothing occurred.
When I upload the .htaccess file to the subdirectory - viewing from all devices returns "The page you requested is NOT AVAILABLE"
The following code is what I was provided by the mobile designers to input into the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
#Check if this is the desktop to mobile query string
RewriteCond %{QUERY_STRING} (|&)m=1(&|$)
#Set a cookie, and skip the next 2 rules
RewriteRule – [CO=mredir:1:%{HTTP_HOST},S=2]
#Check if this is the mobile to desktop query string
RewriteCond %{QUERY_STRING} (|&)m=0(&|$)
#Set a cookie, and skip the next rule
RewriteRule – [CO=mredir:0:%{HTTP_HOST},S]
RewriteCond %{HTTP_USER_AGENT}
“android|blackberry|iphone|ipod|iemobile|opera
mobile|palmos|webos|googlebot-mobile” [NC]
#Check if we’re not already on the mobile site
RewriteCond %{HTTP_HOST} !m\.
#Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(|&)m=0(&|$)
#Check to make sure we haven’t set the cookie before
RewriteCond %{HTTP_COOKIE} !^.mredir=0.$ [NC]
#allow mobile sites to access images on the main site
RewriteCond %{REQUEST_URI} !\.(gif|png|jpe?g|ico)$ [NC]
RewriteRule ^(.*)$ http://example.mobi/ [L,R=301]
</IfModule>
I have ommitted the url that would replace http://example.mobi
I cannot detect if there are any syntax errors in the above code, any help would be greatly appreciated.
Thanks
It's just my guessing. But why do you urge to use .htaccess for simple redirects? If only one site (particular subdirectory on you root / hosting) should always redirect to new, mobile version, then why can't you set a permanent redirect using your server / hosting configuration?
Such tools are in nearly every control panel like cPanel, DirectAdmin etc. Even if your hosting provider runs its own, sophisticated piece of software for running and managing hosting server, I can hardly believe it that it not provide you with any tool or solution for making permanent redirects and thus forcing you to play this game with .htaccess.
BTW: If you 100% sure that you can't do this via server / hosting configuration, and .htaccess is the only way, than maybe this is the right moment to change your hosting? After all, domain / address / URL is the most important for each project, and it can be hosted on any hosting.
As for your problem, I would advice to run second scenario (.htaccess in subfolder) from a regular PC or Linux and via browser equipped with FireBug or simillar developers tool. Then enter your webpage that should do the redirect, but fails, and carefully examine that tool's log / path to see, where you're actually redirected? Is this trully URL you've been expecting? Most times "The page you requested is NOT AVAILABLE" means what it means, that is -- a website tried to redirect your browser to an non-existing URL.
I have found some very useful code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
from another Stack Overflow post:
Remove WWW prefix from your website.
I often re-use the same code on various sub-domains and sites so decided to rewrite a generalised version. I came up with the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
It appears to work, but can anyone give me a reason why I should not use this? Have I missed an obvious flaw?
Edit: I am aware that removing the www has associated issues, but in this case I am more interested in problems arising from writing a generalised htaccess RewriteRule (rather than the actions of the rule itself)
Edit: Code edited as recommended by #ulrich
I would also escape the. otherwise it would match www2.somedomain.com and your %1 would end up being .somedomain.com (if you had such a subdomain configured in the future)
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
If you want to further limit it to just a .com you could use
RewriteCond %{HTTP_HOST} ^www\.(.+\.com)$ [NC]
or .net etc
RewriteCond %{HTTP_HOST} ^www\.(.+\.(com|net|edu))$ [NC]
You may also want to add a RewriteBase / after the RewriteEngine On in case you add other rules to your .htaccess later that need it.
Barring those cases, it should work as is.
The answer lies in this word:
optimization
Here's a full explanation:
http://developer.yahoo.com/performance/rules.html#cookie_free
Quote:
When the browser makes a request for a static image and sends cookies
together with the request, the server doesn't have any use for those
cookies. So they only create network traffic for no good reason. You
should make sure static components are requested with cookie-free
requests. Create a subdomain and host all your static components
there.
If your domain is www.example.org, you can host your static components
on static.example.org. However, if you've already set cookies on the
top-level domain example.org as opposed to www.example.org, then all
the requests to static.example.org will include those cookies. In this
case, you can buy a whole new domain, host your static components
there, and keep this domain cookie-free. Yahoo! uses yimg.com, YouTube
uses ytimg.com, Amazon uses images-amazon.com and so on.
The huge problem lies here: read carefully in bold:
if you don't have your www, all the cookies of your the domain will be sent to all the subdomains. I.e. your have 34 small images in your static.mondomain.com and your website is www.mondomain.com, you have 4 kb of cookies. No problem, all is fine. But if your website is mondomain.com without "www" then all those 4kb cookies will be sent to static.mondomain.com when downloading images, creating a huge and useless loss of bandwidth.
That's what I did when I wrote my version #1, then #2 of my framework. Hopefully my version#3 doesn't do this beginner's mistake, and I hope you'll avoid this too!
Long make short
I'm sorry my English is not very good. What I'm trying to say is: if you plan to have a domain name that does everything (web + images + pdf +... and son on) then use *www*. Otherwise don't use it. The yahoo link explains it better than me.
I am in the process of launching a full website that will be ready in about 6-9 months but I have a self-hosted Wordpress blog created in the meantime to start building a userbase and SEO. So since there will eventually be more to my site than a blog, my blog is located in a subfolder in my root domain (www.website.com/blog). I would like for my root domain (www.website.com) to automatically send users to my blog (www.website.com/blog). Once the full site is ready, I then want my users to enter my domain and be sent to the regular site and not the blog.
Through my searching, it seems like I will either have to set up a 301 or 302 redirect, which I understand how to do. The question is which one to use to prevent negative SEO once the full site launches. I have a feeling I should use a 302 redirect since it is a temporary redirect, but from what I have been reading, it seems like this may hurt my SEO on the popular search engines.
Your help would be greatly appreciated and I can provide more details if needed. Thanks!
I would suggest not to use external redirect and handle this via internal redirect only. That way your URL never changes and search engines will not index wrong URL. In your .htaccess put these rules for this purpose:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/+blog [NC]
RewriteRule ^(.*)$ blog/$1 [L,NE]
RewriteRule ^(/)?$ /blog [R=302]
That should do the trick.