I have several separate Drupal sites. Originally I installed Drupal in a subdirectory, but recently I decided to moved the installation the installations to root. To facilitate the old web addresses to be found I added at the end of the original Drupal .htaccess file the line:

Redirect 301 /drupal/ http://results2match.com/

This works for any site but one (results2match.com).

I identified the offending lines:

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

But removing them is no option, as then only the home page is shown.

My questions:

- What is happening here, and why
- How to solve this, because about 200 links cannot be found

Kind regards, and thanks in advance,

Hans Lodder

Comments

arh1’s picture

yeah, you don't want to remove Drupal's default rewrite rules -- those lines tell Drupal to handle requests for any URL at the site.

and if you add your custom rewrite line to the end of the file, it won't have any effect, b/c the 'L' flag in Drupal's default rewrite rule tells Apache to stop there and not apply any more rules.

you also want to be sure to keep the path from the originally-requested URL with some simple regular expression matching. your rule should be something like this:

RewriteCond %{REQUEST_FILENAME} ^drupal/.*$
RewriteRule ^drupal/(.*)$ /$1 [R=301]

which says: if the requested URL starts with 'drupal/', rewrite the URL from http://example.com/drupal/foo/bar to http://example.com/foo/bar . the [R=301] tells Apache to return a 301 response code, meaning that this address has changed permanently.

(actually i don't know whether the first line is helpful/necessary... maybe someone else can comment on that.)

and those lines should appear above the default Drupal rewrite rules.

that should get you closer, anyway! check out the mod_rewrite documentation for more info.

hth

Hans Lodder’s picture

Hi!

Thanks for your help and encouragement. I tested it immediately, but to no avail. The result is exactly the same. And it remains strange that the suggestions work for all my Drupal 6.9 sites but one!

Furthermore:
- I disabled all 3rd party modules: no change.
- I installed Drupal again: no change.

There are 2 little differences with the other sites:
- I used the supplied default.settings file and edited to reflect my dbms, user, and password
- I defined in my theme the footer in the theme file (still under development)

But those things cannot be the cause, can they?

Any suggestion appreciated!

Kind regards, hans

arh1’s picture

hmm, i'm not sure i understand your setup well enough. can you provide a specific URL that's not being rewritten correctly, and paste the rewrite rules from the site's .htaccess file?

Hans Lodder’s picture

To give an example of such a rule:

Redirect 301 /drupal/why-results2match http://results2match.com/why-results2match

Another example:

Redirect 301 /drupal/rss.xml http://results2match.com/rss.xml

A 3rd example;

Redirect /r2m40contact.html http://results2match.com/contact

I use the latest Drupal 6 release (6.9). I have taken the standard .htacess, put it in the root directory. I moved drupal from the /drupal directory and it is now sitting in the root directory.

I changed the original drupal .htaccess file redirecting all www. traffic to the //results2match.com site. And at the end of the .htaccess I added some specific redirection rules to enable 'old' traffic to find the new location, without drupal in the web address.

from the original Drupal .htaccess file the offending lines:

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Is there othe rinfo that clarify the circumstances?

Regards, and thanks in advance, hans lodder

arh1’s picture

OK, i believe the correct line to add is:

RewriteRule ^drupal/(.*)$ /$1 [L,R=301]

and again, you want to add that *above* Drupal's default rewrite rules.

Hans Lodder’s picture

Thank you! This solution works perfect, and the differnce between my sites have vanished! I can use the same standaard .htaccess file for all 3. As you suggested I did it this way:

# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /

#### End original drupal 6.10 .htaccess file; your suggestion:

# redirect 301 /drupal/ to /
RewriteRule ^drupal/(.*)$ /$1 [L,R=301]

#### Continuing with the original drupal 6.10 .htaccess file:

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]