Forum Moderators: phranque

Message Too Old, No Replies

Redirecting index.html

Please help

         

traffik daddy

3:37 pm on Mar 5, 2006 (gmt 0)

10+ Year Member



Hi,

I am new to this .htaccess rewriting and have a simple problem. I want to redirect my index.html page in the root directory to my index.php page in a sub directory. So my site would be http:www.mydomain.com/index.html and my new homepage would be situated at [mydomain.com...]

Is there a simple command I can use in .htaccess that would redirect them to my index.php page?

Thanks in advance.
TD

stapel

5:52 pm on Mar 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would have thought a simple Redirect would have done the job. But this is not working for you...? Or am I misunderstanding your question...?

Thank you.

Eliz.

traffik daddy

4:29 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



I tried it but for some reason the redirect wont work unless I type in the index.html after the url in the address bar of my browser. So if I type in [domain.com...] it stays as normal rather than my new homepage, only if I type in [domain.com...] it works fine.

Another thing I noticed that when it does redirect it takes out the www prefix in the url.

So it redirects to [domain.com...]

I'm doing this through CPanel. It was my hosts that reccomended using .htaccess.

Are they useless or am I just missing something?

Thanks
TD

jdMorgan

4:35 pm on Mar 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll probably need to by-pass cPanel, and do this 'manually' in .htaccess. You might want to post the code that cPanel is adding to that file, so we can discuss it.

This problem should not be hard to solve on a properly-configured server.

Jim

traffik daddy

4:02 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



I had a look at the .htaccess file, I didn't think for a minute that changing the properties in CPanel would also change the .htaccess file.

Heres what it was putting over when I changed it in CPanel:

RewriteEngine on
RewriteRule ^index/.html$ /zen/index.php
RedirectMatch permanent ^/index.html$ [domain.com...]

Obviously in the URL I just add the www prefix in .htaccess and uploaded.

This brings me to another question although I don't think this is the place for it, if not I apologise.

I have optimised my site and all inbound links are pointing to the raw URL [domain.com....] Redirecting this URL to [domain.com...] will it effect the optimisation on the site for my new homepage? I mean, would I have to optimise my new homepage all over again or would the search engines treat the new page as my old page and I can carry on regardless?

Also, will this pass over the current PR4 of the sites old homepage?

Thanks for the replies, much appreciated.

TD

jdMorgan

8:12 pm on Mar 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems to me that what you want may be a rewrite, rather than a redirect. If you do a redirect, then your server will send a response to the client (browser or search engine robot) that says, "The resource (content) you are requesting has moved. Ask for it again using this new URL." The client must then issue a new HTTP request, using the new URL provided in the redirect response.

This "exposes" your internal site structure to users and the search engines. For the search engines, the redirect tells them to purge the old URL and start using the new one. For SEO purposes, that's not really desirable.

Given the small 'view' I have of your site from the code snippets you've posted, something like this might work better for you:


RewriteEngine on
# Redirect non-www to www domain
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Rewrite index.html requests to /zen/index.php
RewriteRule ^index/.html$ /zen/index.php [L]
#
# -alternate version- commented-out
# This would rewrite requests for [i]either[/i] "/index.html" or just "/" to the /zen index.php file.
# RewriteRule ^(index/.html)?$ /zen/index.php [L]

Note that in order for this to work, pages in "/zen" must refer to included images, stylesheets, and JavaScripts as server-relative or canonical URLs. That is, use <img src="/images/logo.gif"> or <img src="http://www.example.com/images/logo.gif">, and not <img src="images/logo.gif"> or <img src="../images/logo.gif">.

An alternative is to rewrite all image requests as well as page requests, so that changing the page code won't be required. This is possible if the site is highly-organized and the image URLs that need to be rewritten can be easily identified. It won't work well/easily/efficiently if you have images scattered all over the server's filespace. ...Anyway, something to consider.

Jim

traffik daddy

11:03 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Ok, thanks Jim, I'll try that.

Unfortunatly I use Zen Cart which is template/CSS driven so its going to take some altering. All of the images are pointing to /images rather than [domain.com...] and there are many, many spacers.

Thanks again.
TD

jdMorgan

3:41 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the images are point to "/images" then you're fine. If they point to "images" (no slash), then you'll need to take remedial action. I'd suggest you do a quick test and find our.

Jim