Drupal and the missing links.
April 10, 2008 1:48 PM   RSS feed for this thread Subscribe

Drupal: Copying a site to a test site (subdirectory). The links, they go nowhere!

So I followed Drupal's Copying your live site to a test site documentation.

My original site is http://foo.com, and my test site is http://foo.com/test/

I've done the following:
- copied the contents of public/ to public/test/
- done an export of the DB, changed the contents of the export so that any reference to foo.com/ now says foo.com/test/ and done an import to a new DB
- I've added public/sites/foo.com.test/setup.php that points to the new db_url and has foo.com/test as a base_url.

I'm able to access the main page of the test site, and when I mouse over a url it will show foo.com/test/example/ but when I click on it, I get a Page Not Found message, but within the drupal theme. Here's the interesting part... in the page not found page, all the links are from the main site, not the test site.

I wonder if .htaccess has something to do with it. I don't know much about it but here's what's in the .htaccess in public/ :

<IfModule mod_rewrite.c>
RewriteEngine on
# 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]
</IfModule>

I should also mention that I'm using clean urls and Drupal 5.5.
posted by Null Pointer and the Exceptions to computers & internet (10 comments total) 1 user marked this as a favorite
That .htaccess enables clean urls for anything under foo.com, which also eats up anything under foo.com/test. You need to exclude /test from rewriting.

Add this line:
RewriteCond %{REQUEST_URI} !^/(test|test/.*)$
before the RewriteRule.
posted by zsazsa at 2:04 PM on April 10


Yeah, I think you might need to put something like

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/test/.*
RewriteRule ^(.*)$ /test/index.php?q=$1 [L,QSA]

before the rules you've cited. I think zsazsa's way might not work if you want clean urls on the test site too.

And I don't think you need that public/sites/foo.com.test/settings.php in there; Drupal will be looking at /public/test/sites/default/settings.php
posted by bricoleur at 2:15 PM on April 10


With mod_rewrite it's much easier (IMHO) to add a RewriteBase, like so:


RewriteEngine on
RewriteBase /test
# 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]
... etc ...


Other possible culprits:

1. Your template has hardcoded links to your old domain instead of using the proper Drupal base_url variable. BAD designer, no cookie. (If this is the case, your css probably has the same problem in url() statements).
2. make sure no-one hardcoded a base_url in the sites/default/settings.php file.

I find it helps to do a

grep -r 'youroldsitedomain.com' *


in your root drupal path (VERY IMPORTANT unless you want to take forever by searching through your entire server's files) to find instances you might have missed. You can actually also grep your database directory and locate tables that contain the strings too (although in your case, since the domain is similar this probably won't be super useful).
posted by fishfucker at 3:10 PM on April 10


I'm able to access the main page of the test site

oh yeah, for sure this is a rewrite problem then.

(also, 'culprits' was probably the wrong word to use above; bad template links are unlikely to give you a 404 on your test site -- but those are additional issues you might face, and might explain why some links have an incorrect target.)
posted by fishfucker at 3:12 PM on April 10


The mod rewrite suggestion posted by bricoleur here helped a little. Now pages beyond the main page are still marked as not found, but at least on the "page not found" page the urls are all good.

I'm also able to log in, but it can't find any pages after that.

I had already done a grep and nothing is hardcoded as far as paths go, and base_url is not set for the main site.

Any other suggestions?
posted by Null Pointer and the Exceptions at 3:46 PM on April 10


Add a

print $_GET['q'];

to your index.php file so you can see what IS getting passed to the query.

If it's the correct path, perhaps you have a diff problem (maybe one with the path module)
posted by fishfucker at 5:03 PM on April 10


nthing manipulating the RewriteBase line in your .htaccess file. The issue is intimately related to Clean URLs. You should be able to test this by using the 'non-clean' URLs for a bit -- or example, trying http://www.example.com/test/?q=admin/settings/clean-urls and turning them off.
posted by eafarris at 6:01 PM on April 10


eafarris for the win! Well almost. You're right, once I disable clean urls then everything works fine. Now it won't let me reactivate clean urls for the foo.com/test/ instance. Still, this progress is good.
posted by Null Pointer and the Exceptions at 6:44 PM on April 10


Now, you need to manipulate the RewriteBase, probably to
RewriteBase /test

The .htaccess that comes with Drupal should be fine, with the change above. As long as your Apache installation has mod_rewrite loaded you should be ok.
posted by eafarris at 7:02 PM on April 10


Once I disabled clean urls, added the rewrite Base to a .htaccess within the site, and then re-enabled clean urls everything was perfect.
posted by Null Pointer and the Exceptions at 11:36 AM on April 13


« Older What date acquired and cost ba...   |   I'm looking for an inexpensive... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Redirecting a directory to a TLD? June 17, 2008
Redirecting subdomain to https June 11, 2008
How to move files into subdirectories in batch job? November 7, 2006
Redirecting subdomains with mod_rewrite August 19, 2005
How do you do that thing whereby a person can go... November 20, 2004