I have attempted to read various documentation, as well as other answers online, and I cannot find a solution to my problem.

Here is my issue:

I have a permanent www to non-www redirect setup to point traffic from www.example.com to example.com

This works, but I am having issues when trying to visit specific urls. For example:

We have three PDFS that we would like people to be able to download via:


When i visit the url like this it works, but if I try to visit something like this:


The browser gets redirected, and strips one of the slashes out, resulting in "the site cannot be reached error". This is the url I end up with in the browser:


I think its pretty clear that I need to somehow make sure there is a forward slash put before the paper, but I do not know how to do this. Below you will find my .htaccess directive for handling the redirect:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1/ [R=301,L]
  • 1
    Rewrite logging can help you figure out where the slash is being removed. You can use RewriteLog and RewriteLogLevel in Apache 2.2, or LogLevel in Apache 2.4. – Andrew Schulman Jan 16 '18 at 17:07
  • 1
    you would save hassles like this defining virtualhosts as necessary and using redirect/redirectmatch in virtualhost context instead of catch-all rewriterule in per-dir context. – ezra-s Jan 17 '18 at 9:20

Using mod_rewrite seems like an overkill for you. I recommend using mod_alias and its Redirect directive.

    ServerName www.example.com
    Redirect permanent / http://example.com

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.