skip to Main Content

The weirdest thing. Both rewrite rules are working on our Test server but the second one locations is not working on Production and adds a / at the end of locations/ for some reason. The configuration is the same on both servers.

I am trying to simplify the URL without renaming the file. So that if the user enters site.php/locations it will load the content of the redirect page but retain the simplified URL

Any ideas as to why the locations redirect is not working?

RewriteEngine on
RewriteBase /

// The next two are statements are just for context. They preceded the faq and locations forward 
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R=301,L]

// The two rewrites that I want
RewriteRule ^faq$ /faq-mailbox-account.php [NC,L]
RewriteRule ^locations$ /choose-digital-mailbox-location.php [NC,L]

2

Answers


  1. Chosen as BEST ANSWER

    The problem was due to a symbolically linked drive on Prod


  2. … on Production and adds a / at the end of locations/ for some reason

    This will happen if locations exists as a physical directory on the filesystem. (Or existed and the response was cached.)

    If you request /locations and /locations exists as a physical directory then mod_dir will issue a 301 external redirect to append the trailing slash – ordinarily, this is necessary in order to "fix" the URL.

    This external "redirect" by mod_dir will happen regardless of whether your rule matches or not*1, since it is "only" an internal rewrite and not another redirect. (*1 In fact, it does match and the rewrite does occur, but it is effectively overridden by the mod_dir redirect.)

    You could append an optional slash to your RewriteRule pattern, eg. ^locations/?$ – but the redirect will still occur first if you are requesting /locations without the trailing slash. You would need to request a URL that already contains the trailing slash.

    You could prevent mod_dir from appending the trailing slash using DirectorySlash Off, however, this potentially has other implications for your system.

    Note also, that since this is a 301 (permanent) redirect, it will likely be cached persistently by your browser. So, if the /locations directory has since been deleted on the server, the browser will still redirect the user until all client-side caches have been cleared also.

    The configuration is the same on both servers.

    So, there is (or was) a /locations directory on both servers?

    If the configuration is the same on both servers then you would get the same response, so there must be some difference. Or, there is a client-side caching issue.

    So that if the user enters site.php/locations

    I assume you meant site.com/locations – otherwise, the directives you posted have no hope of working, as they simply won’t match.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search