开发者

.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 d开发者_高级运维efine rules.


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}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜