| 8:21 am on Jul 14, 2011 (gmt 0)|
Use a RewriteRule for this. Use [R=301,L] flags too.
There's a couple of thousand previous threads with example code.
| 8:23 am on Jul 14, 2011 (gmt 0)|
|redirect 301 /subdir/ http://www.example.org/ |
only works for the index file, all the other files return a 404 error on the .org site
It's not totally clear what you're trying to do: send each individual file to its counterpart in the other domain, or send everything to the index page in that other domain?
As written, the redirect [httpd.apache.org] takes
and sends it to
This is exactly the way to do it if you have relocated the entire contents of example.com/subdir/ to the top level of example.org.
But if what you are trying to do is send
(written as simply www.example.org/)
then you need a RedirectMatch:
RedirectMatch 301 /subdir/.* http://www.example.org/
in order to take anything within /subdir/ and send it all to the same place.
| 10:20 am on Jul 14, 2011 (gmt 0)|
@lucy: it is the first option i need: i transfered the entire subdirectory to a new domain.
All the pages have there coutnerpart on the .org domain.
Unfortunately the redirect does not work (only works for the index page - the others are redirected to a 404).
From what I have found the line in my first post should transfer it to the right page, no?
I did try :
RedirectMatch 301 /subdir/ http://www.example.org/
to no avail.
I have tried
RewriteRule ^/subdir/$ http://www.example.org/ [L,R=301]
but this redirects to the 404 on the current domain (example.com)
| 12:53 pm on Jul 14, 2011 (gmt 0)|
That's because the pattern you need is
Leading slashes are removed before pattern matching takes place.
The rule with incorrect pattern does not "redirect to a 404". It returns a 404 response at the originally requested URL. 4xx codes are NOT redirects.
Additionally, you do NOT need the $ end anchor as you DO want to match all paths and files under this folder.
If you use RewriteRule for any of your rules, you should use it for all of your rules. That is, do not have Redirect or RedirectMatch directives anywhere else within the same site.
| 1:27 pm on Jul 14, 2011 (gmt 0)|
ok, thanks g1smd.
i am getting closer....
RewriteRule ^subdir/ http://www.example.org/ [L,R=301]
all pages get redirected to the index page on .org.
This is still not what i need, I need the pages to redirect to the corresponding pages on the new domain
|If you use RewriteRule for any of your rules, you should use it for all of your rules. That is, do not have Redirect or RedirectMatch directives anywhere else within the same site. |
Why is this?
PS: I do understand the 404 header is not a redirect in the same sense as the other redirect in this discussion, my choice of words was probably not entirely correct.
| 6:43 pm on Jul 14, 2011 (gmt 0)|
|I need the pages to redirect to the corresponding pages on the new domain. |
I scan read the question.
Add (.*) to the end of the pattern and add $1 to the end of the target.
Redirect and RedirectMatch are processed by mod_alias. RewriteRule is processed by mod_rewrite. The .htaccess file is processed in "per module" order. If a previously rewritten (by mod_rewrite) request is then redirected by mod_alias it will expose the rewritten filepath back out on to the web as a new URL.
| 8:38 pm on Jul 14, 2011 (gmt 0)|
|Redirect and RedirectMatch are processed by mod_alias. RewriteRule is processed by mod_rewrite. The .htaccess file is processed in "per module" order. |
Is there a place in the Apache docs that lists processing order of modules? I swear they used to have a Search and now it's disappeared. (This is not complete delusion. They really did change parts of the site just recently.)
vampke, just to confuse you: the act of redirecting can be performed either by the Redirect (or RedirectMatch) command within mod_alias, or by the Rewrite command within mod_rewrite. Conversely, the act of rewriting or aliasing... well, let's not go there. This is why g1 will always redirect haha .htaccess queries to mod_rewrite. Do it all with the same module and you've got one less thing to worry about. I do not follow this rule.
From the user's POV, the difference between Redirect and Rewrite is that in a redirect their address bar changes and in a rewrite it doesn't.
| 9:00 pm on Jul 14, 2011 (gmt 0)|
Apache module processing order is the reverse order of the module list in the httpd.conf file.
There's an "optimum" order, but also some variation from host to host.
Some configurations can be "problematical".