Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to redirect a broken link onto my site by redirect :

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^domian_registration\.html$ "http\:\/\/mysite\.com\/domain_registration\.html" [R=301,L]

But it responds with error (404 Not Found) and redirects to following URL:

mysite/home/[Cpanel user]/public_html/domain_registration.html

What's the problem?

share|improve this question
up vote 2 down vote accepted

1. Why do you need RewriteCond here that does absolutely nothing?

2. Target URL should be just normal link -- no need to escape all non-alphabet characters like you do \:\/\/.

3. That directive requires mod_rewrite module to be enabled on your server.

That's how your rule should look like:

RewriteEngine On

RewriteRule ^domian_registration\.html$ http://mysite.com/domain_registration.html [R=301,L]

OR as simple as (although including full domain name in URL is recommended):

RewriteEngine On

RewriteRule ^domian_registration\.html$ domain_registration.html [R=301,L]

If you do not have mod_rewrite enabled on your site, you can use this directive instead:

RedirectMatch 301 ^/domian_registration\.html$ http://mysite.com/domain_registration.html

UPDATE: This is an answer for your additional question:

RewriteCond %{QUERY_STRING} ^id=(\d+)
RewriteRule ^maghalat\.php/isfahan_articles(\d+)\.html$ /articles/isfahan_articles$1.html? [R=301,L]

This rule will redirect /maghalat.php/isfahan_articles123.html?id=123 to /articles/isfahan_articles123.html.

Considering that source and target URLs are very similar .. and the fact that id in html file name is the same as id= parameter in query string, we can ignore the query string thus making the rule a bit simpler (no real need for RewriteCond line):

RewriteRule ^maghalat\.php/isfahan_articles(\d+)\.html$ /articles/isfahan_articles$1.html? [R=301,L]
share|improve this answer
thanks , I have another question : how can I redirect mysite/maghalat.php/isfahan_articles([0-9]+).html?id=([0-9]+) to mysite/articles/isfahan_articles([0-9]+).html permanently? – Rega Aug 27 '11 at 9:18
1) What is mysite -- a folder .. or domain name? 2) Provide an real URL example, not with ([0-9]+) – LazyOne Aug 27 '11 at 9:23
did you see my provided link? – Rega Aug 27 '11 at 9:56
See my updated answer – LazyOne Aug 27 '11 at 10:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.