Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

apache - .htaccess rewrite from subdirectory to root

I have some difficulties with the mod_rewrite rules. I want to rewrite any request on

www.example.com/dev/*

to

www.example.com/*

For example when the request url is www.example.com/dev/index.php, the response should be www.example.com/dev/index.php, and not just that the url looks like it's from the root directory, but it is actually using the index.php from root directory.

I have tried the mod_alias which works

RedirectMatch (^/dev/)(.*) http://www.example.com/$2

But it is not possible to apply ip address conditions with mod_alias, so I still need a solution with mod_rewrite.

Would anyone share some knowledge please? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How about something like this?

RewriteRule ^dev/(.*)$ $1

This would need to be in the root folder, or applied to the primary Apache configuration (not in .htaccess).

The usual rules about .htaccess redirects apply - including that RewriteEngine on, Options FollowSymLinks, and AllowOverride FileInfo are included somewhere. Full details at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...