Welcome to WebmasterWorld Guest from 54.196.217.43

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess redirection to forums folder

     
9:37 pm on Apr 1, 2013 (gmt 0)

New User

joined:Apr 1, 2013
posts:3
votes: 0


Hi all,

Please help in setting up a .htaccess redirection which will:

-> redirect example.com to example.com/forum/ and
-> redirect example.com/any-posts.php to example.com/forum/any-posts.php

actually I created a forum a month ago but now need to redirect everything to /forum/ folder.

Thanks!
10:08 pm on Apr 1, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Let's see the code you have already tried.
10:39 pm on Apr 1, 2013 (gmt 0)

New User

joined:Apr 1, 2013
posts:3
votes: 0


Thanks g1smd for reply.

I can do this much:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ forum [L]


got it while searching the net.

It can accomplish half of what I need to do. i.e. the main url but not an internal url of the site.
10:52 pm on Apr 1, 2013 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


welcome to WebmasterWorld, p4kp4k!

it looks like you are trying to do an internal rewrite rather than a redirect.
in that case why are you looking at the hostname?

please describe what type of urls you want to link to in your documents and what the internal paths from the document root look like for those urls.
describe the urls requested and the responses you got for cases that worked as well as cases that failed.
12:15 am on Apr 2, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12700
votes: 244


RewriteCond %{HTTP_HOST} ^(www.)?example.com$


This line is completely out of place here, though you'll use a similar line later on for your domain-name-canonicalization redirect. (Quick Forums search will turn up several hundred examples. The question is asked and answered at least once a week.)

Other than that, the only situation where you'd need to mention the HTTP_HOST is if you've got a single htaccess file serving multiple domains-- and frankly I would try very hard not to do that. At least where mod_rewrite is concerned.

:: uneasily wondering why Forums and/or browser breaks line after "domain-" even though there is plenty of room for "name-" as well ::

the main url but not an internal url of the site.

That's because you cribbed the code from a place using mod_alias (Redirect by that name). mod_alias reappends the rest of the path; mod_rewrite (even when functioning as a redirect) doesn't.
12:25 am on Apr 2, 2013 (gmt 0)

New User

joined:Apr 1, 2013
posts:3
votes: 0


Thanks for update.

I am not that advanced. Just need a re-write rule for mod_rewrite which will:

-> redirect example.com to example.com/forum/ and
-> redirect example.com/any-posts.php to example.com/forum/any-posts.php
6:22 am on Apr 2, 2013 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


from the Apache Web Server forum Charter - http://www.webmasterworld.com/apache/charter.htm [webmasterworld.com]:
It is not appropriate to expect other members to write your code for you or to debug your entire project; Please don't expect other members to solve a problem you don't want to begin solving yourself.