Forum Moderators: phranque
I just noticed a site I am responsible for got into DMOZ but its got the wrong URL -
pointing to a non-exisiting folder without any file name! (sheesh DMOZ editors)
this code doesn't work to fix it, any pointers?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.Ķ )\.mydomain\.com/blah$
RewriteRule ^(.*)$ http://www\.mydomain\.com/new-blah\.htm$1 [L]
%{HTTP_HOST} contains only the host that should handle the request, i.e. www.domain.tld or domain.tld or whatever. Unless there is somethink tricky going on like using mod_rewrite to handle subdomains you usually do not need to test for that. Rewriting takes place after Apache has determined which host/virtual host should handle the request. The syntax for the RewriteRule is
RewriteRule re-matching-URI-path rewritten-URI. There is no need to escape dots in the
rewritten-URI part since it is not a regular expression, i.e. the dot has no special meaning. If the link is DMOZ is [domain.tld...] and you want it rewritten to [domain.tld...] then your RewriteRule would need to look something like this.
RewriteRule ^aaron/$ [domain.tld...] [L,R=301]
You could use the much simpler Redirect [httpd.apache.org]Permanent as well:
RedirectPermanent /aaron [domain.tld ]
Please read An Introduction to Redirecting URLs on an Apache Server [webmasterworld.com] by DaveAtIFG if you havenīt done so yet. We are generally ask not to supply code like this. I made an exception this time. But please be sure to read the introduction and study the mod_rewrite docs. Testing and playing around on a local server will help a lot. Apache is very easy to set up on almost all operating systems.
Andreas
I promise by the end of the day to have read all the
mod_rewrite stuff so I don't re-hash easier stuff like this.
I've got a whole new bookmark folder for mod_rewrite
now and will be reading and practicing shortly :)
Been meaning to do that for awhile now but you know
how little projects get pushed aside when bills have
to be paid. But mod_rewrite is one super serious tool
and I just need to make it a priority to master it.
Thanks again! (what are we up to, 3 pints of cider? :) )