rewriterule is working in conf but not in .htaccess

Alles, was den Apache betrifft, kann hier besprochen werden.

rewriterule is working in conf but not in .htaccess

Postby twelve » 19. January 2012 11:31

Hi,

if a user requests a file in the directory /foo in want the Apache to serve the requested file from /bar.

It works like expected When i use
Code: Select all
RewriteEngine On
RewriteRule ^/foo/(.*)$ /bar/$1

in the configuration file of the virtual host.
But when i place the rule in a .htaccess file nothing happens.
In order to get it to work i have to change it (remove the / of /foo) to
Code: Select all
RewriteEngine On
RewriteRule ^foo/(.*)$ /bar/$1


Coult someone please explain that to me?

regards
Robert
twelve
 
Posts: 12
Joined: 15. February 2006 19:32

Re: rewriterule is working in conf but not in .htaccess

Postby Sharley » 19. January 2012 16:50

Hello Robert.

It is related to paths and the location of the .htaccess and configuration file of the vhost.

They are both in different locations and the vhost file that works is an absolute path starting with / so Apache knows to look in the web root (DocumentRoot) for directory foo.

The foo location path is relative to the .htaccess file which is already in the DocumentRoot so Apache looks for directory foo in the same directory as the .htaccess file is located.

Look up absolute and relative path meanings on the web for a more detailed explanation.

I hope this has helped a little.

Best wishes. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
XAMPP Version: 5.6.3
Operating System: Win 7 Pro 32bit/XP Pro SP3


Return to Apache

Who is online

Users browsing this forum: No registered users and 9 guests