Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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.

like image 939
vicch Avatar asked Dec 23 '11 15:12

vicch


People also ask

What is rewrite rule in htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.


1 Answers

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.

like image 91
ziesemer Avatar answered Sep 23 '22 16:09

ziesemer