Shoaib Nawaz
Shoaib Nawaz

Reputation: 2320

.htaccess how to substitute urls

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.

Upvotes: 0

Views: 1650

Answers (2)

Gumbo
Gumbo

Reputation: 655319

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}

Upvotes: 2

Lekensteyn
Lekensteyn

Reputation: 66425

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

Upvotes: 1

Related Questions