0

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?

1 Answer 1

2

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]
9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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