Forum Moderators: phranque

Message Too Old, No Replies

Redirect dynamic page to homepage

in form of http://www.example.com/

         

chopin2256

3:49 am on Aug 29, 2005 (gmt 0)

10+ Year Member



My site, www.example.com has an index.html page which is the homepage. I want index.html to be the main page of my wiki, but this is not straightforward, since the wiki is in php. My question is, how can I redirect a dynamic page to the index.html?

This is the page I want to redirect:

http://www.example.com/articles/Main-Page

to

http://www.example.com/

I first redirected using this code:

RedirectMatch permanent ^/$ http://www.example.com/articles/Main-Page

Now, how can I convert this to http://www.example.com/?

mipapage

6:49 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you not just use:

RewriteRule ^articles/Main-Page$ http://www.example.com/ [R=301,L]

Not sure if there should be a slash before articles...

jd01

9:15 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, actually that will create a server error...

Not sure I understand what the goal is?

Are you trying to direct people to the inner directory and then back to the main index? If so, why not just remove the first redirect?

Are you trying to serve the information from index.php at the inner directory?

Please, clarify what you are trying to accomplish.

Justin

mipapage

9:30 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not so sure about that server error,

I have:
RewriteBase /
RewriteRule ^random-page/somethin/$ [somedomain.com...] [R=301,L]

And it works just fine...

jd01

9:37 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am:

RedirectMatch permanent ^/$ http://www.example.com/articles/Main-Page

RewriteRule ^articles/Main-Page$ http://www.example.com/ [R=301,L]

Is an infinite loop... user accesses example.com - then they are redirected to /articles/Main-Page - then they are then redirected to example.com - then they are redirected to /articles/Main-Page - then they are redirected to example.com, over and over and over until the server hits the max redirect limit and spits out a 500 internal server error.

Justin

chopin2256

4:38 am on Aug 30, 2005 (gmt 0)

10+ Year Member



I am trying to make http://www.example.com/articles/Main-Page my default index instead of http://www.example.com/index.html

So http://www.example.com/articles/Main-Page should really look like http://www.example.com/

Hope that clarifies it.

I tried this:

DirectoryIndex /articles/Main-Page

And it worked but only problem is http://www.example.com/any-folder/ also redirects to /articles/Main-Page

Very weird

mipapage

4:59 am on Aug 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not wierd, that is expected behavior. It makes the index page of every directory the page that you specified: /articles/Main-Page

RewriteRule ^$ http://www.example.com/articles/Main-Page [R=301,L]

Will redirect requests for your home page to http://www.example.com/articles/Main-Page, and it will change the URL in the browser as well.

You may want to add:
RewriteRule ^index.html$ http://www.example.com/articles/Main-Page [R=301,L]

For anyone who may be linking to that page...

@jd01:
I meant to only use the one, not both.

jd01

7:04 am on Aug 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This would be more efficient and correct:

RewriteRule ^(index\.html)?$ http://www.example.com/articles/Main-Page [R=301,L]

\. = escaping the .(dot) compares a litteral .(dot), not 'any character except the end of a line)

() = grouping

? = 0 or 1 of the preceding characters or gorup of characters.

So, this will rewrite both /index.html and / to /articles/Main-Page correctly.

Justin

chopin2256

5:28 am on Aug 31, 2005 (gmt 0)

10+ Year Member



I got the redirect to work, but the link displays like this:

http://www.example.com/articles/Main-Page

How do I convert that now to just http://www.example.com/

jd01

5:53 pm on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmmm,

Back to my first question - what exactly are you trying to do?

Are you trying to get the information from the deep location to the root level?

You will need to take out the Redirect and serve the information from the deep directory:

RewriteRule ^(index\.html)?$ /articles/Main-Page [L]

If you do not remove the first redirect:

RedirectMatch permanent ^/$ http://www.example.com/articles/Main-Page

You will have a conflict and people will not be able to access your home page, they will all be redirected to the inner page.

Justin