John John - 2 months ago 12
Apache Configuration Question

Apache localhost double www.domain (not host) directory rewrite

I have to provide public access in certain circumstances to a client domain from the main business domain. I'm working to get this to work locally first (

.local.htaccess
) and therefore only need help with the local system's rewrite rule please. These domains are not the host (host is
localhost
) though I test all manners of access (192., 127., etc).

Requested URL

https://localhost/Version-1.0/www.example1.com/www.example2.com/images/waldo.gif


File Server Path

https://localhost/Version-1.0/www.example2.com/images/waldo.gif


.local.htaccess Location

https://localhost/Version-1.0/.local.htaccess


The general code I've been tinkering with:

RewriteEngine on
RewriteRule ^[.*/].*/(www.)+/images/(.*)$ $1/images/$2


I've had success with the scripts directory (all rules, though not the images directory) using the following (the images directory even with an otherwise empty
.htaccess
file):

RewriteEngine on
RewriteRule ^[^/].*/scripts(.+) scripts$1

Answer

Try this rule as your very first rule in your .local.htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(Version-1\.0)/www[^/]*/(www[^/]*/\S*)\s
RewriteRule ^ /%1/%2 [L,NE,R=301]
Comments