Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite problem

Trying to get it to work in a sub-directory

         

MrSpeed

2:35 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to rewrite php urls into static looking html. I have done this before when the site is at the root but I am having a harder time if the site is in a directory.
The structure of my url's have a few different combinations
[/mysite.com/ea/category/...]
[/mysite.com/ea/category/subcategory/...]
[/mysite.com/ea/category/subcategory/product.html...]

I'm trying to rewrite to
[/mysite.com/ea/products.php?parameters=$parameters...]

In my php script I parse out the $parameters which usually end up as
ea/category/
ea/category/subcategory/
ea/category/subcategory/product.html

Here is the .htaccess I was using to do this. I placed it in the /ea/ folder.

RewriteEngine on
rewritebase /ea
RewriteRule (.*)/(.*) products.php?parameter=$1/$2

I pretty much got it to work with trial and error.
I don't quite understand the rewritebase
I tried to figure it out at
httpd.apache.org/docs/mod/mod_rewrite.html

And now for the tricky part.
I wanted to take a url like this
[/mysite.com/ea/special/some-thing/...]
and send it to
[/mysite.com/ea/special.php?keywords=$1...]

I created the .htaccess like this:

RewriteEngine on
rewritebase /ea
RewriteRule (.*)/(.*) products.php?parameter=$1/$2
RewriteRule topitems/(.*) special.php?keywords=$1

The problem is that this new url seems to be following the first rule.
I tried reversing the order of the rule and just about every iteration of
slashes and wildcards I could.

To tell the truth I think I need to come up with a whole new .htaccess

As I've said I've gotten this exact same setup to work when the site is at the root.

jdMorgan

5:43 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MrSpeed,

For use in .htaccess, the following code should work. Be sure to flush your browser cache (Temporary Internet Files) before testing a new set of rewriterules. Otherwise, the page will be fetched from your cache and not from the server. In that case, your rewriterules can have no effect. You may have to force a reload if your ISP caches pages as well -- Use control-reload or shift-reload, depending on the browser you're using.


RewriteEngine on
RewriteBase /ea
RewriteRule ^topitems/(.*) /special.php?keywords=$1 [L]
RewriteRule ([^/]*)/(.*) /products.php?parameter=$1/$2 [L]

Jim

MrSpeed

6:29 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jim-
That almost worked. I just had to add the "/ea/" directory to the php pages. I would have though that the rewritebase would handle that?

RewriteEngine on
RewriteBase /ea
RewriteRule ^topitems/(.*) /ea/special.php?keywords=$1 [L]
RewriteRule ([^/]*)/(.*) /ea/products.php?parameter=$1/$2 [L]