views:

14

answers:

2

How can I substitute URLs of a web application in a sub folder as installed on root.

e.g. need to map example.com/index.php to example.com/new/index.php

I do not want redirection but url rewrite to exempt folder name.

Help me to learn and define rules.

A: 

The first line matches all requests not matching /new/... and prefixes it with a new before it.

RewriteCond %{REQUEST_URI} !^/new/
RewriteRule ^(.*)$ new/$1

Request: http://example.com/index.php
Maps to: [document root]/new/index.php

Lekensteyn
+1  A: 

You can use the following rule to rewrite any request that’s URL path (without path prefix) does not start with new/:

RewriteCond $1 !^new/
RewriteRule ^(.*)$ new/$1

This will also work in .htaccess files other than in the document root directory.

But as you want to use this rule in the .htaccess file in the document root directory, you could also use REQUEST_URI:

RewriteRule !^new/ new%{REQUEST_URI}
Gumbo