Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite resolving the entire URL!

Redirecting instead of internally rewriting

         

BigBadBurrow

10:35 am on May 15, 2005 (gmt 0)

10+ Year Member



Hello,

I've just changed web hosts and experiencing a strange problem with the mod_rewrite. If I try to access one of our pages via the mod_rewrite, it resolves the URL. E.g. I click on the link with this URL: http://www.example.com/dolphin-pcitures-cat.htm
but mod_rewrite resolves it to: http://www.example.com/subcategory.jsp?category=dolphin-pictures

i.e. rather than http://www.example.com/dolphin-pictures-cat.htm being displayed in my browser I get http://www.example.com/subcategory.jsp?category=dolphin-pictures, which I don't want. I want it to stay http://www.example.com/dolphin-pictures-cat.htm

It didn't do this on my old webhost, so I'm thinking there must be something set-up wise which is different on my new host. Any ideas?

Here is the rewrite rule:

RewriteRule ^(([0-9]+¦[a-z]+¦[-]+)+)-cat\.htm$ http://www.example.com/subcategory.jsp?category=$1&%{QUERY_STRING}

Many thanks,

BBB

[edited by: jdMorgan at 3:51 pm (utc) on May 15, 2005]
[edit reason] Removed specifics per TOS. [/edit]

krt1

11:23 am on May 15, 2005 (gmt 0)

10+ Year Member



Adding the [r] flag to the end of the RewriteRule code will redirect the user and show the new URL so take off the [r] flag.
Your situation is odd however as you don't appear to be using the [r] flag.
Not too sure.
Can you give the URL where this is happening?

BigBadBurrow

11:28 am on May 15, 2005 (gmt 0)

10+ Year Member



<snip>

[edited by: jdMorgan at 3:29 pm (utc) on May 15, 2005]
[edit reason] No URLs, Please see TOS. [/edit]

BigBadBurrow

12:11 pm on May 15, 2005 (gmt 0)

10+ Year Member



I've been looking through the httpd.conf file and come across this:

<Directory />
Options All
AllowOverride All
</Directory>

<Directory "/home/hickerph/tomcat/webapps">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Do you think I need to change AllowOverride None to AllowOverride All for
<Directory "/home/hickerph/tomcat/webapps">?

jdMorgan

3:40 pm on May 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BBB,

Welcome to WebmasterWorld!

There are two basic URL changes that mod_rewrite can do. It can do an external redirect, which involves telling the client (e.g. browser or search engine robot) to re-request the resource from a different URL. This, by definition, updates the URL in the browser's address bar. Or it can do a server-internal rewrite, essentially changing the filename associated with a requested URL.

The problem here may be that your syntax is specifying half of each type of function. You should choose one or the other.

External redirect:


RewriteRule ^(([0-9a-z]+-)+)cat\.htm$ http://www.example.com/subcategory.jsp?category=$1&%{QUERY_STRING} [R=301,L]

Internal rewrite:

RewriteRule ^(([0-9a-z]+-)+)cat\.htm$ /subcategory.jsp?category=$1&%{QUERY_STRING} [L]

Based on your statement that you don't want the address bar to change, the internal rewrite is appropriate.

If this doesn't help, then it's likely you have another rule or configuration setting that is invoked, and is causing the external redirect.

I recommend that you do not set "Allow all" on any directory that does not require it. I also recommend that you do not specify "Options MultiViews" unless you are using content-negotiation on your site. The first recommendation is a security concern, and the second can greatly affect server performance.

Jim

BigBadBurrow

7:13 pm on May 15, 2005 (gmt 0)

10+ Year Member



Thanks jdMorgan! It's working now. It's weird how it worked fine on one host, but not the other - must be a setting somewhere.

Thanks for the welcome :D