Forum Moderators: phranque
I have several rewrite conditions:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://mystore.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mystore.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mystoreshop.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mystoreshop.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mystore.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mystore.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mystoreshop.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mystoreshop.com$ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mystoreshop.com/.*$ [NC]
RewriteCond %{HTTP_REFEER} !^https://www.mystoreshop.com$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]
Options +FollowSymLinks
RewriteEngine on
#
# Canonicalize the domain name: Redirect if the requested
# hostname is non-blank and is NOT precisely "www.mystoreshop.com"
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mystoreshop\.com$
RewriteRule (.*) [mystoreshop.com...] [R=301,L]
#
# Internally rewrite root directory requests to /store
RewriteCond $1 !^store/
RewriteRule (.*) store/$1 [L]
Does it matter which site I put for "YOURSITE.COM" below? Is there a better way to protect your site then using the example below.
For example:
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
RewriteCond %{HTTP_REFERER} ^http://www.YOURSITE.COM$
RewriteRule !^http://[^/.]\.YOURSITE.COM.* - [F,L]
This stuff confuses me I am embarrased to say. Camille
Options +FollowSymLinks
RewriteEngine on No need to duplicate it further down the page.
.
The code for the ten RewriteCond lines can be considerably simplified, to just two lines, I think:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mystore(shop)?\.com/.* [NC]
RewriteCond %{HTTP_REFERER} !^https://www.mystoreshop.com/.* [NC]
RewriteRule .*\.(jpe?g¦gif¦png¦bmp)$ - [F,NC] Note the simplification in the file extensions list too.
.
Are you sure you want *all* to be redirected?
# Internally rewrite root directory requests to /store
RewriteCond $1 !^store/
RewriteRule (.*) store/$1 [L] What about /robots.txt or your Google/Yahoo/Live WMT user-ID verification file?
Should the $1 be %1 on the first line ... like this?
# Internally rewrite root directory requests to /store
RewriteCond [b]%1[/b] !^store/
RewriteRule (.*) store/$1 [L] Actually, that rule might be completely wrong. I might be completely wrong.
.
This line is incorrect:
RewriteRule !^http://[^/.]\.YOURSITE.COM.* - [F,L] RewriteRule sees the only the folder and filepath, not the host name.
Do you need another RewriteCond to test %{HTTP_HOST) there?
Additionally, [F] always implies [L] so you can just use [F] and it will work just fine.
Fix up your code as far as you can, then repost it here.
A couple of years ago this stuff was complete rocket science to me, so I do feel your pain.
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mystore(shop)?\.com [NC]
RewriteCond %{HTTP_REFERER} !^https://www\.mystoreshop\.com [NC]
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ - [F,NC]
Syntactically, the following rule is correct: You *do* want to use the $1 back-reference to the matched RewriteRule pattern, and not a %n back-reference to the preceding RewriteCond matched pattern (in this case, there is none, so it would be undefined):
# Internally rewrite root directory requests to /store
RewriteCond $1 !^store/
RewriteRule (.*) store/$1 [L]
Jim
[edited by: jdMorgan at 4:57 pm (utc) on Sep. 26, 2008]
Noting that you provided for HTTPS in the referrer-based rule, I would add that if you do use HTTPS, then your domain canonicalization rule will need to be duplicated (or modified), so that both http and https domains are canonicalized without changing the protocol from https to http, or vice-versa.
The simplest approach is:
# Canonicalize the domain name: Redirect if the http-requested
# hostname is non-blank and is NOT precisely "www.mystoreshop.com"
RewriteCond %{SERVER_PORT} [b]!^4[/b]43$
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mystoreshop\.com$
RewriteRule (.*) http://www.mystoreshop.com/$1 [R=301,L]
#
# Canonicalize the domain name: Redirect if the htt[b]ps[/b]-requested
# hostname is non-blank and is NOT precisely "www.mystoreshop.com"
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mystoreshop\.com$
RewriteRule (.*) htt[b]ps:[/b]//www.mystoreshop.com/$1 [R=301,L]
Jim
[edited by: jdMorgan at 5:45 pm (utc) on Sep. 26, 2008]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mystore(shop)?\.com [NC]
RewriteCond %{HTTP_REFERER} !^https://www\.mystoreshop\.com [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]
# Canonicalize the domain name: Redirect if the http-requested
# hostname is non-blank and is NOT precisely "www.mystoreshop.com"
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mystoreshop\.com$
RewriteRule (.*) [mystoreshop.com...] [R=301,L]
#
# Canonicalize the domain name: Redirect if the https-requested
# hostname is non-blank and is NOT precisely "www.mystoreshop.com"
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mystoreshop\.com$
RewriteRule (.*) [mystoreshop.com...] [R=301,L]
# Internally rewrite root directory requests to /store
RewriteCond $1 !^store/
RewriteRule (.*) store/$1 [L]
You mention that it is recommended to write exceptions. I'll have to read about this. What is the draw-back to not having exceptions?
Im still working on the protection part..
Basically, it is quite uncommon to want to rewrite *absolutely all* URL requests to a script.
Jim
The search engine forums often discuss what you may need to do to prevent ranking problems -- such things as protocol, domain, URL, and query canonicalization. In general, we discuss *how* to implement these things here, and not so much of the "why."
I'd imagine you could spend six months reading posts here at WebmasterWorld and studying the underlying server documentation. And that would be a fairly good start... ;) The more you know and learn now, the fewer problems you might have to address in the future; We get posts all the time saying things like, "I changed all of my URLs, and my site has not been listed in the search engines for eith months now!" To which the answer is, "Yes, that can happen if you change your URLs, but now it's too late to go back..."
Such things make me sad, because a little research before making such a drastic change would have saved a lot of grief -- and in some cases, it might have saved a company from going bankrupt from lack of Web traffic after changing all their URLs and losing all of their PageRank and TrustRank.
It is more than just linked pages that are inter-connected on the Web; The operation of a server can and does have drastic effects on the search engine ranking of pages on a site, and 'everything matters' unless the documentation (server, scripting language, shopping cart, database, forum, blog, search engine, etc.) says it doesn't.
Anyway, we hope you'll stick around, read (a lot), and enjoy WebmasterWorld.
Jim