.htaccess - Simulating virtual host wrong link to Parent Directory in Directory Listing
Posted
by
?????? ?????
on Server Fault
See other posts from Server Fault
or by ?????? ?????
Published on 2013-01-10T13:58:54Z
Indexed on
2013/10/20
21:57 UTC
Read the original article
Hit count: 190
I have a domain dedicated for my local server (.dev), and an .htaccess file which redirects requests like http://folder.dev/subfolder/
to /htdocs/folder/subfolder
. It works great and all, except for one minor issue. When I have the Directory Listing enabled, I can access all the folders, subfolders and files properly, except when I click on the Parent Directory
link, which, for example, should lead to http://folder.dev
, but redirects to http://folder.dev/folder/
and consequently throws 404 not found
. Similarly, if Parent Directory
should link to http://folder.dev/subfolder/
, it links to http://folder.dev/folder/subfolder/
. Here's how my .htaccess looks like:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.dev\.?(:80)?$ [NC]
RewriteCond %2 !^www|ftp|mail|pop3|localhost$
RewriteCond %{DOCUMENT_ROOT}/%2 -d
RewriteRule ^(.*) %2/$1 [E=SUBDOMAIN:%2,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN}]
Apart from that one thing, everything else works fine (e.g. relative links in documents etc.)
© Server Fault or respective owner