Forum Moderators: phranque

Message Too Old, No Replies

another .httaccess 301 issue

         

blizzster

4:42 am on Nov 6, 2010 (gmt 0)

10+ Year Member



Hi guys, I spent the last 5hrs pulling my hair off on this. I am just trying to help someone out.

I am trying to permanently redirect all traffic from:
www.mysite.com to www.mysite.com/mysite

This was accomplished by doing:

Redirect 301 /index.html [mysite.com...]

Now my problem is when people browse to www.mysite.com they see the subfolder and I need to hide that. I have way too many other folder in the root and can't move them.

I made this base on several posting and didnt work right:
RewriteEngine On

RewriteRule ^index.html$ [mysite.com...] [R=301,L]

RewriteRule (.*) /mysite/ [NC,L]

did I missed something? I tried to use a code from previous postings...

sublime1

6:18 pm on Nov 7, 2010 (gmt 0)

10+ Year Member



Make sure you understand the distinction between a RewriteRule that results in an external redirection ("R=301") versus an internal rewrite.

Here's your example annotated:

# When a request comes in requesting index.html from the document root,
# respond with an HTTP 301 response ("move permanently") providing a new location
# and stop processing rewrite rules
RewriteRule ^index.html$ http://www.mysite.com/mysite/ [R=301,L]

# When any request comes in return the content at /mysite/
# using an internal rewrite and stop processing further rules... however
# if done in a .htaccess context, the rewritten URL will be rechecked and
# match again, probably resulting in a recursive loop.
RewriteRule (.*) /mysite/ [NC,L]
[code]

Do you want [i]all requests[/i] to start in /mysite/? (e.g. a request for [code]http://www.mysite.com/image.jpg
would return an image whose file location is mysite/image.jpg, relative to the document root)? If you have just moved the enture site from the document root do the mysite subdirectory, you could probably set RewriteBase to /mysite/. But if you want the /mysite/ directory to be visible to users, then you need to do a 301 redirect.

In short, it is entirely unclear to me what you are attempting, what behavior you actually want, and why. Examples are very helpful.

Tom

blizzster

11:41 pm on Nov 7, 2010 (gmt 0)

10+ Year Member



Thanks sublime1 for your response.

So this is my current situation. I was working on this website and now someone else is taking over. I have a lot of content in that domain root and I did not want that person to access. So I created subfolder with the wwww.mysite.com, an ftp user account with full access to that folder www.mysite.com/mysite and moved all the content into that folder. This way the person can do whatever he needs. With a regular redirect, you can see the folder structure in the address bar and that's i tried to use this rewrite rule...

I need to wait till the contract is over for me to make any changes or move things out. In the meantime I am stuck.

I guess RewriteBase is what I need to do... I how do i use the rewritebase? I hit a search on that Asap... Thanks...

jdMorgan

12:47 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Externally redirect direct client requests for URL-paths starting with /mysite back to root URL-path
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /mysite/
RewriteRule ^mysite/(.*)$ http://www.example.com/$1 [R=301,L]
#
# Internally rewrite requests for URL-path /index.html to filepath /mysite/
RewriteRule ^index\.html$ /mysite/ [L]
#
# Internally rewrite all requests to /mysite subfolder, unless already done
RewriteCond $1 !^mysite/
RewriteRule ^(.*)$ /mysite/$1 [L]

Jim