views:

40

answers:

2

Is this qood example of redirection of page to another domain page:

RewriteCond %{HTTP_HOST} ^dejan.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www.dejan.com.au$
RewriteRule ^seo_news_blog_spam\.html$ "http\:\/\/dejanseo\.com\.au\/blog\-spam\/" [R=301,L]

or good old works too:

301 redirect seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

and whats the difference?

A: 

Presumably, the rules are functionally equivalent (well, assuming that http://dejanseo.com.au/blog/spam/ was supposed to be http://dejanseo.com.au/blog-spam/ like the first one redirects to, and the only host pointing at that location is dejanseo.com.au with or without the www).

The first example uses directives from mod_rewrite, whereas the second one uses some from mod_alias. I imagine that the preferred option is the second one for this particular case, if not only because it's a bit simpler (there's also marginal additional overhead involved in creating the regular expressions being used by mod_rewrite, but that's very minor):

Redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog-spam/

However, I suspect the reason that you have the first one is that it was created using CPanel (based on the unnecessary escapes in the replacement that appeared before in another user's question where it was indicated CPanel was the culprit). They've gone with the mod_rewrite option because it provides conditional flexibility that the Redirect directive does not, and I assume this flexibility is reflected somewhat in whatever interface is used to create these rules.

You'll note that there is a condition on whether or not to redirect based upon your host name in the first example, identified by the RewriteCond. This allows for you to perform more powerful redirects that are based on more than just the request path. Note that mod_rewrite also allows for internal redirects invisible to the user, which mod_alias is not intended for, but that's not the capacity it's being used in here.

As a final aside, the host names in your RewriteCond statements should technically have their dots escaped, since the . character has special meaning in regular expressions. You could also combine them, change them to direct string comparisons, or remove them altogether (since I imagine they don't do anything useful here).

Tim Stone
i forgot to include most important thing and that is that seo_news_blog_spam.html file needs to redirect to another domain URL. Does mentioned technique works with redirecting to another domain instead of just redirecting to local URLs?
purpler
@purpler - Yep. For both `Redirect` and `RewriteRule`, you can put a fully qualified URL as the replacement to redirect to another domain. Note that if the domains point to the same server and document root, you'll need to use the `RewriteRule` + `RewriteCond` version, as host checking is required in that scenario to avoid a redirect loop.
Tim Stone
A: 

Unbeliavable, the problem was that the synthax wasn't correct, so instead of:

redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

it should look like this:

Redirect 301 seo_news_blog_spam.html http://dejanseo.com.au/blog/spam/

One, first big letter was the source of all troubles, what a waste of time :D it works now as it supposed to! Thanks to everyone who participated, issue solved.

purpler