Forum Moderators: phranque
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]
<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">?
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]
RewriteRule ^(([0-9a-z]+-)+)cat\.htm$ /subcategory.jsp?category=$1&%{QUERY_STRING} [L]
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