Forum Moderators: phranque

Message Too Old, No Replies

Problem with rewrite rules

         

gravima

7:36 am on Jun 23, 2010 (gmt 0)

10+ Year Member



Hi,

we have published a completely new version of our website few days ago [dolphin-therapy.org...] and everything is working fine with redirection, except one thing.

But first some backgrounds. We have the following structure on our webserver

/ => (old Joomla system)
/dolphin-therapy/ => (new Joomla system)
/dolphin-therapy/blog/ => (new Wordpress system)

What do I do in the different folders?

/
Here I have prepared a big .htaccess file for redirecting single old pages to the corresponding new url
And if no special page is found I have general redirection at the end of the file:
RewriteCond %{HTTP_HOST} ^delphintherapieweb\.de$
RewriteRule ^(.*)$ http://dolphin-therapy.org/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www\.delphintherapieweb\.de$
RewriteRule ^(.*)$ http://dolphin-therapy.org/$1 [L,R=301]


/dolphin-therapy/
Here I´m redirecting:
RewriteCond %{HTTP_HOST} !^dolphin-therapy\.org$
RewriteRule ^(.*)$ http://dolphin-therapy.org/$1 [L,R=301]

... [further Joomla stuff for SEF URLs]

/dolphin-therapy/blog/
Here I´m redirecting:
RewriteCond %{HTTP_HOST} !^dolphin-therapy\.org$
RewriteRule ^(.*)$ http://dolphin-therapy.org/blog/$1 [L,R=301]

... [further Wordpress stuff for SEF URLs]

Now our problem:
If I open
www.dolphin-therapy.org/blog 


I´m getting things strange result:

dolphin-therapy.org/blog//kunden/homepages/15/d262578252/htdocs/dolphin-therapy/blog


It does not happen when I call
www.dolphin-therapy.org/blog/ 

(with trailing slash)

I know it has something to do that the rules are getting in conflict with each other but I doesn´t find a solution.

If needed I can also provide more details. Thanks for every help.

Regards,
Steffen

jdMorgan

2:31 pm on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have evidently put your rules in the wrong order, and have failed to use the [L] flag on some rules.

Since you left out the Joomla and WP code, I can't tell exactly.

As a result, a previously-rewritten URL-path, having been converted to an internal filepath by that rewrite, is being 'exposed' to the client by a subsequent redirect.

Don't arrange your code by "domains, Joomla, Wordpress". Arrange your code by access controls first, external redirects next, internal rewrites last, with the rules in each of these three sections ordered from most-specific patterns and conditions to least-specific patterns and conditions.

BTW, the first two rules above can be combined into one. Just replace the Hostname pattern with "^(www\.)?delphintherapieweb\.de" to make the "www." optional. Do NOT end-anchor this pattern.

The current third rule has a latent potential 'infinite loop' lurking in it. To fix it, change the pattern to "!^(dolphin-therapy\.org)?$" so that blank hostname requests will NOT be redirected.

Jim

gravima

6:14 pm on Jun 23, 2010 (gmt 0)

10+ Year Member



Hi Jim,

thanks for you quick reply. I have checked your hints, but still I have not a clear idea why it can occur. As far as I have seen I have no missing L in my files. So I think it is the best if I share my complete .htaccess files

Root folder (old URL / system):
RewriteEngine on

# Redirection of the most important indexed Joomla pages
RewriteCond %{query_STRING} option=com_content&task=view&id=16&Itemid=277&lang=english
RewriteRule ^index\.php$ http://dolphin-therapy.org/en/dolphin-therapy/dolphin-assisted-therapy-concept? [R=301,L]

[... here comes ~80 single redirects but all in the same style]

RewriteCond %{query_STRING} option=com_content&task=view&id=100&Itemid=127&lang=Italian
RewriteRule ^index\.php$ http://dolphin-therapy.org/it/terapia-con-i-delfini/in-generale? [R=301,L]

# General language redirection if pages above was not found
RewriteCond %{query_STRING} lang=english
RewriteRule ^index\.php$ http://dolphin-therapy.org/en? [R=301,L]

[... here comes 6 more language redirects in the same style]

RewriteCond %{query_STRING} lang=Russian
RewriteRule ^index\.php$ http://dolphin-therapy.org/ru? [R=301,L]

# General redirection if nothing above found
RewriteCond %{query_STRING} option
RewriteRule ^index\.php$ http://dolphin-therapy.org? [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?delphintherapieweb\.de
RewriteRule ^ http://dolphin-therapy.org/ [R=301,L]


Folder /dolphin-therapy (new URL / system)
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^dolphin-therapy\.org$
RewriteRule ^(.*)$ http://dolphin-therapy.org/$1 [L,R=301]

## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]

########## Begin - Joomla! core SEF Section
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
########## End - Joomla! core SEF Section


Folder /dolphin-therapy/blog (new WP system in subfolder blog)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(dolphin-therapy\.org)?$
RewriteRule ^(.*)$ http://dolphin-therapy.org/blog/$1 [L,R=301]

# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress


Thanks again for the help!

Regards,
Steffen

jdMorgan

10:05 pm on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again, put the "Deny access" rule first. Also its flag should be just [F], not [F,L] -- The [L] is redundant when used with [F].

I don't see anything in this code which would do what you describe. The root .htaccess appears to have no rules that would apply, to a request for "www.dolphin-therapy.org/blog. The .htaccess file in /dolphin-therapy/ won't be applied, because it is not in the /blog filepath, and the /blog .htaccess only contains the (badly-coded) WP rewrite rule.

There are many opportunities to clean up this code -- some of which may visibly imrove your server's performance under load. But those issues can wait until the main problem is resolved.

I would suggest trying the following:

Set Options -MultiViews to disable content-negotiation unless your site relies on it.
Set AcceptPathInfo off to turn off Path-info "rewriting" unless your site relies on it.
Set CheckSpelling off to disable mod_speling unless your site relies on it.

If those setting smake no difference, then contact your host and/or admin, and find out what is in the server configuration files. Look for additional mod_rewrite rules, and any mod_alias directives that may be affecting the requests for your /blog URL-paths.

Somewhere, somehow, a URL-to-filepath transaltion is being invoked before a www- to non-www redirect, and the latter redirect is exposing the filepath. (I assume that this is NOT the www- to non-www redirect in your /dolphin-therapy/.htaccess file, because that .htaccess file should NOT execute for requests to the /blog filepath -- UNLESS there is an additional internal rewrite in the server config file that is doing that.

Anyway, there's something wrong with your server configuration, and the problem is not within the code you posted.

Jim

jdMorgan

10:08 pm on Jun 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, that's a really good question. You say that last bit of code is in /dolphin-therapy/blog/.htaccess.

But there is no visible code to 'map' any requests to /dolphin-therapy, so that code should never run...

How do requests for "www.dolphin-therapy.org/blog" get mapped to /dolphin-therapy/blog ? -- That is where your problem may lie...

Jim

gravima

11:22 pm on Jun 23, 2010 (gmt 0)

10+ Year Member



Hi Jim,

thanks again for your detailed thoughts and hints.

Your mentions what I can try is in the Joomla / Wordpress stuff. I´m not an mod_rewrite expert and don´t want to "touch too much"

And I´m sorry, that I did not get your last point that requests for "www.dolphin-therapy.org/blog" get not mapped to /dolphin-therapy/blog ?

I thought that the following code (I had previously) doing this?

RewriteCond %{HTTP_HOST} !^dolphin-therapy\.org$
RewriteRule ^(.*)$ http://dolphin-therapy.org/blog/$1 [L,R=301]


In your first answer I understood you suggest me to replace this by the code as in my last post. Do you have any further concrete tipp what I can try to solve this?

Thanks again!

Regards, Steffen

jdMorgan

12:04 am on Jun 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since that is an external redirect, it is a URL-to-URL translation, not a URL-to-filepath translation, and therefore cannot be responsible for the problem you're seeing.

I suspect that you have a server misconfiguration problem. Unless you have access to your server config files and feel confident re-configuring your server, I suggest that you contact your host for assistance.

Also, since you don't want to 'touch too much' just be aware that if your site begins to get overloaded and slow, you might want to consider using some of the improved Joomla and WP code posted in this forum before you pay for a server upgrade. Their 'standard' code is poorly-written and inefficient.

Jim

gravima

8:51 am on Jun 24, 2010 (gmt 0)

10+ Year Member



Hi Jim,

I already have contacted my host. But they told me, they cannot give support because it seems to be a conflict of my htaccess files. I will contact my host again.

But one thing I don´t understand. You say it is NOT a URL-to-filepath translation.

But my problem again is the redirection from / to:
http://www.dolphin-therapy.org/blog
http://dolphin-therapy.org/blog//kunden/homepages/15/d262578252/htdocs/dolphin-therapy/blog


This doesn´t seem to be a external redirect (URL-to-URL)?

Regards, Steffen

jdMorgan

4:01 pm on Jun 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is indeed an external redirect. and that is why the redirected-to URL-path should not contain the filepath, which it obviously does...

Something is badly broken. This problem would not occur with this code on any of my servers.

Jim