Forum Moderators: phranque

Message Too Old, No Replies

To much rewrite , think

         

Xoverride

5:21 pm on Feb 3, 2008 (gmt 0)

10+ Year Member



I'm having problems with a website of mine. I'm using a rewrite script I got with the help form this form (thank again :) ) , but I think to much is being rewritten. When I use this script:
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}!^(www\.example\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule .* http://www.example.com/example/exampleaccount.form?account=%2 [P,L]

xoverride.example.com works fine and www.xoverride.example.com also, so no problems there! The problem however is when I click on some links on the site. I have for example a link on the site that makes a request to /createholiday.form . when I click this link I get the wrong page, i get exampleaccount.form . I don't know if anything is rewritten because if you are on xoverride.example.com, you can type everything you want, eg. xoverride.example.com/blabla.form , and you still would get the exampleaccount.form. Why is this?

When you don't use the xoverride.example.com, but you use the example.com?account=xoverride everything works fine. The funny thing is, when I click on createholiday.form from this url, a request is being made to /application/createholiday.form and not just /createholiday.form. (application is the name of the application).

I have a proxy configured for /example so everything that request a url preceeding with /example will be put through the proxy using AJP. This could be the reason the in the first scenario is works and the second it does not. But why is the second different? why is there not application in front of /createholiday.form. Is this because the url was already rewritten for the first time?

Anyway, can this issue be solved? Is there way to fix this, knowing that /createholiday.fom is requested, can we somehow rewrite this also?

We have createholiday.form but also createparty.form, and so on. All have 1 thing in common, they end with .form .

It is possible that there are some parameter behind e.g. createholiday.form?parameter=3&test=true , something like this could be rewritten to:
http://www.example.com/example/createholiday.form?parameter=3&test=true

What are your thoughts about:
- the difference between /application/createholiday.form and /createholiday.form

- my rewrite thoughts, can this be done? how?

jdMorgan

9:38 pm on Feb 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One thing at a time, please. You will get more and better responses with a single well-focused quaestion at a time.

For example, what is the purpose of the rule that you're having trouble with? The solution to your problem depends rather strongly on what you are trying to accomplish with that rule.

As shown, it will proxy any request for any resource (e.g. "page") in any subdomain except "www" to /example/exampleaccount.form?account=%2 in the canonical www.example.com domain.

So it's fairly obvious what the rule actually does, but not obvious what you really want it to do.

Jim

Xoverride

9:31 am on Feb 4, 2008 (gmt 0)

10+ Year Member



You are right, let me explain better.

At this moment a request that's being made to for example xoverride.example.com is being rewritten to http://www.example.com/example/exampleaccount.form?account=xoverride. This is good.

I have some links on the webpage that will make a request to /createholiday.form /checkpics.do , /createparty.form?partyid=3 , and so on ... there are 3 different file extensions .form .do and .ajax

These links should also be rewritten, so the link:
/createparty.form?partyid=3 , should become

http://www.example.com/example/createparty.form?partyid=3

the same goes for /createholiday.form, /checkpics.do . etc...

jdMorgan

8:01 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I'm guessing, here...

If you only want URL-paths ending in .ajax, .do, and .form to be handled by this rule, then change the RewriteRule pattern to make it more specific. You may also need the first RewriteCond to prevent looping:


RewriteCond %{REQUEST_URI} !^/example/exampleaccount\.form$
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule \.(ajax¦do¦form)$ http://www.example.com/example/exampleaccount.form?account=%2 [P,L]

Important: Replace the broken pipe "¦" characters above with solid pipe characters before use: Posting on this forum modifies the pipe characters.

Jim

Xoverride

8:48 am on Feb 5, 2008 (gmt 0)

10+ Year Member



Jim, In your code , this will not work will it?

the link:
/createparty.form?partyid=3 , should become

http://www.example.com/example/createparty.form?partyid=3
In your example it will be rewritten to exampleaccount.form, right?

What do you think about this? Do you think this is correct?

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST}!^(www\.example\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.+)$ http://www.example.com/example/$1 [P,L]

RewriteCond %{HTTP_HOST}!^(www\.example\.com)?$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ http://www.example.com/example/exampleaccount.form?account=%2 [P,L]

jdMorgan

12:48 am on Feb 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I understand exactly what you want, but perhaps this is closer:

RewriteCOnd %{QUERY_STRING} !^account=
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com
RewriteRule ^([^.]+\.ajax¦do¦form)$ http://www.example.com/example/$1.form?account=%2 [P,L]

Replace the broken pipe "¦" characters above with solid pipe characters before use: Posting on this forum modifies the pipe characters.

Jim