Forum Moderators: phranque

Message Too Old, No Replies

Root not working after subfolder redirect

         

OmarW

4:24 am on May 22, 2009 (gmt 0)

10+ Year Member



Hello, I have redirected the domain root to a sub-folder. Everything is working fine except that I can't access any files within the root. I want to be able to access root in addition to the redirect. Can anyone help me with the code accomplish this?

Here is the code in the .htaccess file in the root httpdocs folder:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/store/
RewriteRule ^(.*)$ /store/$1 [L]

This is the URL for the root: [store.example.com...] where this is pointing.

Any help will be really appreciated.

[edited by: jdMorgan at 1:36 pm (utc) on May 22, 2009]
[edit reason] example.com [/edit]

jdMorgan

1:40 pm on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This isn't clear. Please post some example URLs that you *do* and *do not* wish to be rewritten to the /store/ subdirectory.

Be aware that mod_rewrite will base its decision to invoke the rewrite only on the URL requested by the client, so *some* information must be carried in the requested URL that will allow it to make the correct decision;. In other words, you can't write the code to rewrite *all* requested URL-paths to the /store/ filepath, and then expect to be able to access root unless there is something distinct about "root URLs" that you can tell mod_rewrite to identify and use to inhibit the rewrite.

Jim

g1smd

7:37 pm on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Using (.*) says you want to rewrite "all" requests, so you'll need to adjust that pattern to match only URL requests that do need to be rewritten.

OmarW

9:38 pm on May 22, 2009 (gmt 0)

10+ Year Member



Thanks for the responses. I am using Miva Merchant software so how would I do it so that only requests to the file merchant.mvc? (and eventually admin.mvc?) are forwarded?

I tried replace it with this code but it gave a server error message:
RewriteCond %{REQUEST_URI} !^/store/merchant.mvc
RewriteRule ^(.*)$ /store/merchant.mvc$1 [L]

jdMorgan

11:20 pm on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Rewrite requests for merchant.mvc and admin.mvc to /store/merchant.mvc and /store/admin.mvc
RewriteRule ^(merchant¦admin)\.mvc$ /store/$1.mvc [L]

Important: Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe characters.

The RewriteCond is no longer needed, since the rewritten filepath will no longer match the URL-path pattern.

Jim

OmarW

4:34 am on May 23, 2009 (gmt 0)

10+ Year Member



Jim, Thanks for the response and code. It works very well.
Thanks,
Omar