Redirect works, pass-through does not

cn flag

Our CMS has a handler named root, which works: serves, what we want it to serve.

We'd like requests for "naked" domain ( to be handled by that same handler automatically -- without requiring /root to be part of the request.

What I expected to "just work" -- results in a 404:

RewriteRule ^/*$ /root [L]   # Results in 404

The best I can come up with is a redirect, which exposes the name root:

RewriteRule ^/*$ /root [R=permanent,L]   # Works

How can I do this without redirecting? I tried adding PT to no avail...

us flag
I think you should change your CMS configuration instead, so that the base URL is set properly. If you rewrite incoming request URLs, the CMS will still generate URLs that have `/root` prefix, which means you'll end up having duplicate content.
cn flag
Thanks, but `/root` is not a directory here -- nor is it otherwise a prefix...
us flag
So static resources and JS are served from `/` instead? How about other pages under `/root`?
cn flag
Again, there is no "under"... Requesting serves content. We want requests for (with or without slash) to be served _the same_ content...
kz flag
RewriteRule ^/*$ /root [L]

This is OK, however, whether this works is dependent on how your CMS reads the requested URL. The CMS will most likely be reading the originally requested URL (that's included in the HTTP request headers), not the URL that has been internally written to. So, the CMS sees /, not /root. And if it doesn't see / as a valid route then you get a 404.

Most CMSs would break if they read the rewritten URL, since most CMSs use a front-controller pattern and internally rewrite all requests to a common script (the "front-controller"). Reading the rewritten URL in this case will serve no purpose since it will always be the same (ie. the URL of the front-controller).

Rewriting the requested URL in this way will not work with WordPress, Joomla, Drupal, etc. etc.

Only if your CMS provides a mechanism for explicitly overriding the requested URL (eg. with a URL parameter perhaps) can you do this at the server level, otherwise, you need to configure this route in the CMS itself. (ie. Preferably changing the URL/route from /root to /, rather than adding this as an "alias", which could potentially cause duplicate content issues.)

cn flag
Thanks, this explains, why we're having a problem. But as for solution -- besides digging into the CMS innards, is not there some flag for mod_rewrite, that would change the passed URL too (without a redirect)?

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.