: Redirect does not work 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"
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?
More posts by @Odierno851
1 Comments
Sorted by latest first Latest Oldest Best
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$ 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$ 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.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.html? [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.