Apache's VirtualDocumentRoot configuration requires a change in drupal's htaccess file, or Clean URLs will break. This tiny adjustment (the leading / on index.php) is very difficult for anyone to know about, and VERY difficult to discover or fix when your drupal installation isn't working. By adding these few lines to htaccess explaining what lines to use for what configuration, some (admittedly not all) of those user's will find this in htaccess and solve the problem more easily.
# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
becomes
# Rewrite current-style URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For standard virtualhosts
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
# For virtualdocumentroot
#RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
See these nodes for more details about the issue: http://drupal.org/node/86667 http://drupal.org/node/8147
Note, on brief testing, using the slash in typical VirtualHost configurations seems not to break Clean URLs, although further testing would be required.
Comment | File | Size | Author |
---|---|---|---|
#25 | htaccess_18.patch | 1.56 KB | Bevan |
#20 | htaccess_17.patch | 2.04 KB | Bevan |
#12 | htaccess_16.patch | 1.27 KB | Bevan |
#5 | htaccess-leading-slash.patch | 350 bytes | Bevan |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedExcuse my poor eyes. I don't see the difference between this
and this
except for the comment character.
Comment #2
Bevan CreditAttribution: Bevan commentedMy Bad. Sorry.
This is the line in current distributions:
This is what works for VirtualDocumentRoot configurations
This is the patch I propose for .htaccess to make life easier for those trying to find / solve this bug. (I've also tidied up the comments.)
Comment #3
drummThis is not a patchfile, see http://drupal.org/diffandpatch.
Comment #4
Bevan CreditAttribution: Bevan commentedSorry that I don't know everything thing yet.
Please read 'change' when I say 'patch'.
I'll try and know everything.
Comment #5
Bevan CreditAttribution: Bevan commentedGod damn! I've just spent 4 hours debugging my server, to find this #¬¢∞·&$% leading slash was the error. +1 (A really big one) to get this into drupal six.
Now that I've learnt how to do patches... Attached.
Comment #6
slantview CreditAttribution: slantview commentedI've also fixed this by changing these lines:
To
Comment #7
Bevan CreditAttribution: Bevan commentedI've recently learned my patch breaks installations running in sub directories.
B/
Comment #8
Anonymous (not verified) CreditAttribution: Anonymous commented@bevan: Have you tried slantview's suggestion at #6? Does it work for you?
Comment #9
Bevan CreditAttribution: Bevan commented#6 works for me and is a better solution than the one I suggested. So I suggest this patch instead:
This will require that sites running in subdirectories modify .htaccess for the site to work. However I think this is the case already for sites running in subdirectories. It's definitely the case for sites running in subdirectories of a VirtualDocumentRoot, can someone with regular VirtualHost please confirm?
If I'm wrong, and sites running in subdirectories of a VirtualHost don't normally need modifications to .htaccess, then this patch will probably now require modifications to those sites' .htaccess. In that case I'll rework this patch.
Comment #10
dman CreditAttribution: dman commentedI think you are thrashing a bit, and creating problems for yourself. Putting an absolute path or leading slash into the config file makes it much less general-purpose.
In my experience, RewriteBase is totally optional, indeed to be avoided unless all else fails. It's an over-ride that should not be neccessary unless the paths are confused.
I have a dozen Drupal instances running in subdirs, or multisites, or multisites in subdirs, also addressed via virtual hostnames etc - on one apache virtualhost development machine.
RewriteBase is not required, and must not be. Adding a RewriteBase for one site breaks it for the rest.
I've not worked with VirtualDocumentRoot , but I hope there is a more graceful fix to your problem.
Comment #11
slantview CreditAttribution: slantview commentedI'm sorry, I would have to agree with dman on this. The specific fix I gave is for VirtualDocumentRoot only. I would not suggest uncommenting that in the main file as it is the exception, not the rule. If you want to contribute a patch back, you should add a comment to the file that uncommenting that particular line will help us users with VirtualDocumentRoot.
I have worked on lots and lots of Drupal sites, and only our development server has needed that and one time I used it for Rewriting in a sub-directory.
Glad the fix worked for you however.
Comment #12
Bevan CreditAttribution: Bevan commentedI wondered if that was the case. Thanks for clarifying. Well this has all boiled down to a few additional comments. I also tidied up other comments in the file for consistency. I noticed that the Id CVS keyword is at the bottom in this file. Normally it's at the top right? Any known reason for this exception?
Comment #13
dman CreditAttribution: dman commentedUseful comments and documentation are a welcome contribution, but the patch is a bit unclean, not sure why (line endings? whitespace?)
Perhaps you could describe exactly what you had to do as a handbook page contribution!
As I said, I don't know about VirtualDocumentRoot, (it's an edge case for me) but I think your comments to the file are appropriate.
But some more detailed clarification would be good. (They would be good for the original comment also ;-)
Comment #14
Anonymous (not verified) CreditAttribution: Anonymous commentedAs dman pointed out the patch is unclean with spacing issues. Also, please use the unified difference switch, it is more pleasing to the eyes.
Comment #15
Bevan CreditAttribution: Bevan commentedare these the spacing issues you refer to?
I added some line breaks and whitespace to make the code and comments easier to read and more consistent throughout the file. I think this is important, as comments in .htaccess are probably the most often-read by newbies.
How do I do cvs diff with the 'unified difference switch'?
@dman
A handbook would be a good supplement to this, but I think it's important to include some mention of VirtualDocumentRoot in .htaccess. The aim of this issue is to make it easier for users of drupal to solve clean URL issues. Currently there is no reason for a drupal user to think that their VirtualDocumentRoot configuration might break it (This is arguably an issue with Apache/VirtualDocumentRoot, but apache developers have washed their hands of it and "won't fix" -- I can't find the link right now). Therefore attempts to fix the issue are often trial and error (as mine were the first time). This is tedious and frustrating.
Most of this trial and error work happens in .htaccess. Therefore htaccess is the best place to let the user know that VirtualDocumentRoot will break clean URLs (and offer a fix for it). When users start trying to solve an unknown problem, I think many search documentation or read inline comments -- particularly the latter in the case of issues surrounding htaccess.
Comment #16
dman CreditAttribution: dman commentedYeah sure, do both. Add a line about it in the htaccess yes, but actually explain what the exact problem is and why that workaround fixes it in a documentation supplement.
Because .htaccess is an important place for many custom set-ups, it's important to note what the side-effects may be also. To avoid even more trial-and-error or follow-on breakages.
Comment #17
chx CreditAttribution: chx commentedI am inclined to won't fix this. Where do you draw the line between making htaccess comments for every possible Apache configuration? Virtualdocumentroot is quite an advanced feature, if you are running that then you know what are you doing. If your site runs that then they should have a support article on it like http://modwest.com/help/kb1-292.html . I do not see a proper patch to be worked with so I changed the issue to be active.
Comment #18
Bevan CreditAttribution: Bevan commentedI wouldn't have considered VirtualDocumentRoot an advanced configuration. It might be uncommon, but it's quite simple to set up. I'm not a sysadmin -- I mostly do theming work with drupal and some consulting -- and I set it up in MAMP to make it quick and easy to deploy new dev sites -- no restart required; http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html#virtualdocumen...
I have the same number of lines in my included apache .conf file as I would have for one virtualhost.
Also I suspect it's uncommon-ness is largely thanks to lack of support for it -- mostly on the part of apache, but also from projects like drupal.
Why *should* we draw a line? There is a finite number of apache configurations, and even if we catered for every single one the comments and/or documentation would still be valuable and usable. I agree it's important to make these comments as concise and clear as possible, and to make the more common issues more prominent. And move detailed documentation into the handbook.
Can someone please answer my question; How do I do cvs diff with the 'unified difference switch'?
Comment #19
chx CreditAttribution: chx commentedcvs diff -up http://drupal.org/patch
Comment #20
Bevan CreditAttribution: Bevan commentedThanks chx! :)
Comment #21
Anonymous (not verified) CreditAttribution: Anonymous commentedThe patch is better to read but still needs work.
The removal of the space for example
doesn't make the comments easier to read. Please adjust the patch without those changes.
Comment #22
Bevan CreditAttribution: Bevan commentedThose lines aren't comments. They are directives that can be uncommented to have an effect on the configuration. To make them consistent with the other commented-out directives in the file, I removed the space between the first character of the directive and the pound-sign. This also marks the directives distinctly from the comments and makes them easy to distinguish.
Comment #23
dman CreditAttribution: dman commentedApropos of nothing, "£" is the Pound sign. "#" is the HASH sign.
Yes, they may appear on the same place on UK/US keyboards, but there's no other good reason for confusing them.
I actually understood the "Comments that may be uncommented" better without the extra space, as per this patch, but it's certainly not worth making things difficult about..
Comment #24
Anonymous (not verified) CreditAttribution: Anonymous commentedBut they are comments none the less and for standard structure a space needs to follow it. I'm being difficult about it because others will be even more so.
Comment #25
Bevan CreditAttribution: Bevan commentedI think it enhances usability without the space -- but it's really not worth wasting more time over. If you thinks it's important, then here you go (attached).
Comment #26
slantview CreditAttribution: slantview commentedHi Dan,
Just as a follow up, in the United States / Canada the "HASH" character is often referred to as the "pound" sign. You can find references at http://en.wikipedia.org/wiki/Number_sign
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commentedI think the patch is ready.
I changed the Component to other because File System wasn't correct and nothing else fits.
Note to committer: This is a documentation only patch to help clarify the need to define or change RewriteBase value.
Comment #28
Gábor HojtsyAgreed. Modified the docs to have a colon after the "following line" texts, to be in line with other comments in the file. Committed.
Comment #29
dman CreditAttribution: dman commentedFirst, yay for a commit that may help this reasonably trivial issue get to rest.
Second, thanks for the reference that explains why # may mean "pounds" to some folk (what do you call £ ? ). So maybe there is a reason beyond keyboard layouts to confuse it. I've only ever seen [the hash sign #] out-of-context meaning "number' but we learn every day. I forgot that some folk don't do decimal yet. I'd only ever known of the currency version, and not considered the legacy/imperial version. interesting.
Comment #30
(not verified) CreditAttribution: commentedComment #31
Bevan CreditAttribution: Bevan commentedThis went into drupal 5.7: http://drupal.org/node/215269
Comment #32
8thom CreditAttribution: 8thom commentedThanks for this work.
I run my local dev environment in VirtualDocumentRoot mode however I often work on sites that don't, so whenever I clone a repo that doesn't, I need to set the Rewritebase. Also, if the .htaccess file is committed it becomes modified and your local repo can never be clean
Not a major but can be annoying....
Anyhow I've just found a decent solution by overriding the default .htaccess file.
Just set the AccessFileName in the Virtualhost directive, I used the following :-
AccessFileName .htaccess.local .htaccess
(I've also added .htaccess.local to the global git ignore file.)
This means if you clone a site that needs the RewriteBase set you can just copy the .htaccess file as .htaccess.local uncomment this line and you're good to go.
It also won't affect other sites as it will only override if .htaccess.local is found.
Just throwing it out there incase anyone else has similar issues.
Comment #33
Bevan CreditAttribution: Bevan commentedThanks 8thom! That's good to know. Btw, I stopped using
VirtualDocumentRoot
when I switched to Acquia Dev Desktop for my (L)AMP stack on Mac OS X.Comment #34
8thom CreditAttribution: 8thom commentedMust give Acquia Dev Desktop it a try sometime.
Just been burnt too many times developing on WAMP/MAMP.
Do you know if there's plans to release Acquia Dev Desktop on Linux?
I also quite like developing on a VM as it's portable, can keep this stable (Ubuntu LTS) and still do major OS upgrades plus it's bonus to be able to snapshot the VM for those highly experimental changes which may require changes to server config, DB and code.