Forum Moderators: phranque
I'm desperately trying to make a redirection from
http://www.mydomaine.com
&
http://mydomain.com
to: http://www.mydomaine.com/blog
BUT
I got several other registered url that redirect to dedicated subfolders contained in this domain webspace,
(example : http://www.web2.com redirects to http://www.mydomain.com/web2)
When my htaccess is working for the first part of my question, it always fail with the others domains,
can someone please help
Thanks thanks a lot !
[edited by: jdMorgan at 10:27 pm (utc) on Oct. 18, 2008]
[edit reason] de-linked URLs [/edit]
Also, can you tell us why you would want to *redirect* from mydomaine/ to mydomaine/blog, instead of simply serving the content for the URL mydomain/ from the filepath /blog ? By this I mean that there is no reason that the users or search engines would know or care that content for mydomaine/ was stored in mydomaine/blog, and so there is no reason to tell them that it is. Instead, simply *rewrite* from mydomaine/ to /blog, and the clients don't need to know about this filespace mapping inside the server, any more than they need to know about the other domains that mentioned mapping into their own subdirectories.
Jim
Here is what I'm using right now :
RedirectMatch permanent ^/$ http://www.mydomain.com/blog/
This code works when I'm typing http://www.mydomain.com only, not when I'm typing http://mydomain.com (first problem)
To answer you, I want to use this redirection not to move all the files I've created with database and so on in my /blog folder.
The webspace connected to this general domain in fact stores a lot of other websites files, that's why i'm embarassed with this redirection problem. All the other domains url now also redirect to mydomain/blog, I assume they do that because they go into the htaccess file and dont maybe find exceptions.
i'm sorry I'm not that good in english, nor in htaccess.
Thanks for your help.
[edited by: jdMorgan at 10:29 pm (utc) on Oct. 18, 2008]
[edit reason] de-linked URLs [/edit]
Next, look at the HTTP_HOST header again. Verify that it is www.mydomaine. If so, and the requested URL-path *does not* start with /blog, then *internally rewrite* to /blog, retaining whatever additional URL-path-parts the client asked for.
Jim
That is certainly the best way to tackle things
Is it? If I understand the problem correctly, the aim is to redirect one page, specifically the root index page, to one particular subdirectory, this without affecting any other subdirectory which may also function as a document root for another domain.
If this is an accurate description of the scenario, then I don't think using mod_rewrite is the simplest solution. A simpler and more robust solution would to be to have an index.php in the document root which includes the following:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/blog/");
?>
I'm wondering why you think the PHP solution is "more robust" as well, since it depends on loading and executing an additional interpreter -- and not a small one, either. That's quite an additional dependency to introduce into a conventionally-assessed "robustness" analysis.
Jim
When discussing robustness, one of my pet hates is the "stacking" of document roots where either subdomains or addon domains have their document root within a subdirectory or another domain. This always complicates the use of mod_rewrite as the .htaccess for the main domain affects those domains/subdomains in the subdirectories. Changing this setup will help the "robustness" as the complexity of any rewrites is usually reduced.
I think it's fair to suggest that the question should not always be how to use mod_rewrite to achieve a goal, but to ask whether mod_rewrite is always the solution. Not every problem is a nail to be hit with the mod_rewrite hammer. :)
When discussing robustness, one of my pet hates is the "stacking" of document roots where either subdomains or addon domains have their document root within a subdirectory or another domain. This always complicates the use of mod_rewrite as the .htaccess for the main domain affects those domains/subdomains in the subdirectories.
It's possible --and yet to be fully-determined-- if this is the case in the OP's server set-up.
I think it's fair to suggest that the question should not always be how to use mod_rewrite to achieve a goal...
Jim
[edited by: jdMorgan at 2:13 am (utc) on Oct. 19, 2008]
The main operation of the sub-folder is mapped to another domain with its own .htaccess file, so the .htaccess in the server _public_html or _www root folder only comes into play if the sub-folder is being referenced by the "wrong" domain name. None of the other sub-folders are affected by this.
However, you should take steps to get rid of any links pointing to the old/wrong URL, because it will avoid the search engines and visitors having to be redirected. View the redirect as a "tidy-up" and not as a "cure." If you cannot get all Web sites which point to the wrong URL to correct their links, then the 301 will need to remain in place forever.
There is no way to put HTML elements such as <title> into a server response header. But it doesn't matter because even if you could, they wouldn't be used anyway; The <title> and everything else will be taken from the new URL instead.
Jim