Forum Moderators: phranque

Message Too Old, No Replies

I'm having some Problems with ModRewrite

Having some problems with ModRewrite

         

Stewart81

6:26 pm on May 16, 2009 (gmt 0)

10+ Year Member



Hi All,

I am hoping someone here can help me. I have been googling quite a bit this morning looking for a solution but nothing is catching my eye.

I have this in my .htaccess located in a demo folder:

RewriteEngine On
# Rewrite static URLs to dynamic
rewritecond %{REQUEST_URI} !^(/demo/products/)
rewritecond %{REQUEST_URI} !^(/demo/categories/)
rewritecond %{REQUEST_URI} !^(/demo/articles/)
# uncomment the above line if you have the article add-on installed
RewriteRule (.*)\.htm$ /demo/proddetail.php?prod=$1
rewritecond %{REQUEST_URI} ^/demo/categories/
RewriteRule ^/demo/categories/([^.]+)\.htm$ /demo/categories.php?cat=$1
rewritecond %{REQUEST_URI} ^/demo/products/
RewriteRule ^/demo/products/([^.]+)\.htm$ /demo/products.php?cat=$1
#rewritecond %{REQUEST_URI} ^/demo/articles/
#RewriteRule ^/demo/articles/([^.]+)\.htm$ /demo/viewarticle.php?artid=$1
# uncomment the above 2 lines if you have the article mod installed

# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /demo/proddetail\.php\?prod=([^&]+)\ HTTP/
RewriteRule ^/demo/proddetail\.php$ [mysite.com...] [R=301,L]


If it I remove /demo/ throughout the .htaccess and move it to the primary folder it works great, but no matter what I can't get it to work from within the demo folder. It is sending all .htm requests to /demo/proddetail.php so it seems to me that it is ignoring the rewrite conditionals set above that.

I am just hoping someone here will see my mistake :)

Thanks,

Stewart

jdMorgan

9:52 pm on May 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In a .htaccess context, or within a <Directory> container in a server config file, mod_rewrite does not "see" the path to the current directory, only the path to files in this directory and to files in subdirectories below this directory. Therefore, you'll need to remove the leading slash from your RewriteRule patterns.

RewriteConds testing REQUEST_URI) *will* see the leading slash, but many of your RewriteConds are redundant because they test the same URL-path as the following RewriteRule. You can get rid of those redundant RewriteConds.

Jim

g1smd

10:58 am on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should list the redirect first, before all of the rewrites.

Add the usual non-www to www redirect after your existing redirect and before all of your rewrites.

Add the [L] flag to every one of your rewrites.