I want to redirect my urls via htaccess from a particular sub-folder to main domain.
One option is to use the following rule
RewriteRule ^subfolder/(pattern)$ http://%{HTTP_HOST}/$1 [R=301,L]
works fine for real domain
redirects correctly
http://example.com/subfolder/page
to
http://example.com/page
works incorrectly for localhost
redirects
http://localhost/exmple/subfolder/page
to
http://localhost/page
instead of
http://localhost/exmple/page
modifying the rule as follows works for localhost but not for real domain
RewriteRule ^subfolder/(pattern)$ http://%{HTTP_HOST}/example/$1 [R=301,L]
I use localhost environment for development and testing before uploading the script to the host web server.
Please tell if this is possible to handle the above scenario in a generic way so that I don't need to maintain two copies of code/htaccess - one for local and one for real domain.