Forum Moderators: phranque

Message Too Old, No Replies

root level rewrite

         

sebenza

6:14 am on Feb 10, 2006 (gmt 0)

10+ Year Member



Hi Folks-
I have been trying to do a root level htaccess rewrite and have ran into a snag. Hopefully someone here will know more than I do on this.

Here is an example of my rewrite and URL format:

# Category Rewrite
RewriteRule ^(.*)\.html /shop/index.php?page=c&ccode=$1
# Product Rewrite
RewriteRule ^(.*)/(.*)\.html /shop/index.php?page=p&pcode=$2&ccode=$1

Category URL:
[domain.com...]

Product URL:
[domain.com...]

Everything works fine until I try to access the /links/ directory. It is still trying to load the /shop/index.php stuff. Any ideas? Thanks!

jdMorgan

2:41 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not clear on the specific problem you have, but three points:

1) Most-specific rules go first
2) Use more-specific patterns -- avoid ".*" if possible
3) Stop the rewrite engine using [L] unless you need to process more rules after the one that matches

Like:


# Product Rewrite
RewriteRule ^([^/]+)/([^.]+)\.html$ /shop/index.php?page=p&pcode=$2&ccode=$1 [L]
# Category Rewrite
RewriteRule ^([^.]+)\.html$ /shop/index.php?page=c&ccode=$1 [L]

Jim

sebenza

4:34 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Thanks for the tips Jim-

The problem I have is that we also have a /links/ directory.

When I try to access:

domain.com/links/index.html

It tries to load:

domain.com/shop/index.php?page=p&pcode=index.html&ccode=links

How can I get the links directory to load correctly? Thanks again!

jdMorgan

4:47 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Exclude slashes from the RewriteRule patterns:

# Product Rewrite
RewriteRule ^([^/]+)/([^./]+)\.html$ /shop/index.php?page=p&pcode=$2&ccode=$1 [L]
# Category Rewrite
RewriteRule ^([^./]+)\.html$ /shop/index.php?page=c&ccode=$1 [L]

Jim

sebenza

5:09 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Here is what I have in my htaccess and it still loads the /links/ page in the /shop/index.php file:

RewriteEngine On
RewriteCond %{REQUEST_URI}!-s

DirectoryIndex /shop/index.php

# Product Rewrite
RewriteRule ^([^./]+)/([^./]+)\.html$ /shop/index.php?page=p&pcode=$2&ccode=$1 [L]

# Category Rewrite
RewriteRule ^([^./]+)\.html$ /shop/index.php?page=c&ccode=$1 [L]

Any other ideas? Thanks!

jdMorgan

7:29 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK,

Just exclude that page from being rewritten by any rule it otherwise might match:


# Product Rewrite
# This rule matches requests for /<directory>/<filename>.html
#
# exclude /links/ directory
RewriteCond %{REQUEST_URI} !^/links/index\.html$
# rewrite everything else
RewriteRule ^([^./]+)/([^./]+)\.html$ /shop/index.php?page=p&pcode=$2&ccode=$1 [L]
#
#
# Category Rewrite
# This rules rewrites all URLs of the form /<filename>.html
# except for those rewritten by the rule above
RewriteRule ^([^./]+)\.html$ /shop/index.php?page=c&ccode=$1 [L]

Jim

sebenza

7:53 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



I think that will do it. Thanks for all the assistance!