1

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:

example.com/paper/somepdfname.pdf

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

www.example.com/paper/somepdfname.pdf

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:

example.compaper/somepdfname.pdf

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] 
2
  • 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. Commented Jan 16, 2018 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. Commented Jan 17, 2018 at 9:20

1 Answer 1

0

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

NameVirtualHost 111.22.33.44:80 <VirtualHost 111.22.33.44:80> ServerName www.example.com Redirect permanent / http://example.com </VirtualHost> 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.