0

I'm using a Red Hat Apache web server (2.4.6). The Apache is adding "/" at the end of URL if directories are accessed (default behaviour) through http 301. I want to avoid http 301 by the Apache web server while accessing directories. So I have done this.

<Directory /var/www/html>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride all
 DirectorySlash Off
</Directory>

I noticed DirectorSlash Off stopped Apache from automatically adding "/" to directories in the URL.

I added the below at the end of httpd.conf but it has no effect. I don't see the below is adding "/" to the directory in the URL. The Rewrite rules are not firing. Any idea what's wrong.

RewriteEngine on
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ $1/ [P]

Thanks in advance.

  • What is wrong is you turned off the redirect. Turn it back on. – Michael Hampton Jun 26 at 19:33
  • @MichaelHampton Sorry, couldn't understand you. Can you please elaborate? – Lord Gane Jun 26 at 19:41
  • It's extremely unlikely that you are in a situation where you should be turning off DirectorySlash. This causes a lot of subtle changes, and is not recommended. What exactly is the purpose of this? What do you intend to accomplish overall? – Michael Hampton Jun 26 at 19:42
  • I've a server where a third party product is installed. Let's call it server1 which acts as a Reverse Proxy. server1.com sends requests to downstream Apache web server. Let's call it server2. When there is no trailing slash at the end e.g. server1.com/apple, the request as usual goes to server2 and the server2 is issuing a http 301 on browser i.e. server2.com/apple. I don't want this to happen because server2 is not directly accessible on browser so the flow is breaking. So, that's the reason why I disabled "DirectorySlash" on Server2 and want to use RewriteRules. – Lord Gane Jun 26 at 19:47
0

Based on your comments :

I've a server where a third party product is installed. Let's call it server1 which acts as a Reverse Proxy. server1.com sends requests to downstream Apache web server. Let's call it server2. When there is no trailing slash at the end e.g. server1.com/apple, the request as usual goes to server2 and the server2 is issuing a http 301 on browser i.e. server2.com/apple. I don't want this to happen because server2 is not directly accessible on browser so the flow is breaking. So, that's the reason why I disabled "DirectorySlash" on Server2 and want to use RewriteRules.

The problem is NOT in your Apache configuration on server2.

And that is also not where you should be trying to fix this.

The problem is that the reverse proxy is not configured correctly. A reverse proxy should recognize the redirect headers backend servers send and rewrite those to the URI used by the front-end reverse proxy.

On a Apache reverse proxy that is done by the ProxyPassReverse directive.

On nginx that usually happens correctly but when the back-end server uses URI’s in redirect headers that don’t match the one used in the proxy_pass definition you need to fine-tune that with the proxy_redirect directive.

Other reverse proxy’s will have similar options. ...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.