homepage Welcome to WebmasterWorld Guest from 54.198.8.124
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod rewrite problem
ddregallo




msg:3235290
 1:00 am on Jan 29, 2007 (gmt 0)

I'm developing a site around a php shopping cart. The URLs it uses are not SE friendly.

They look like this.
www.site.com/index.php?page=products

I'm using mod_rewrite to turn them into this
www.site.com/products

The problem I'm having is that the rewrite rules I put in .htaccess don't seem to be doing anything. If I link to www.site.com/products I get 404 not found error. My webhost supports the feature. Here is my .htaccess. Any ideas what I'm doing wrong?

Options All -Indexes

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/products/([0-9]+) /index2.php?crn=$1
RewriteRule ^/articles/([0-9]+) /index2.php?article=$1
RewriteRule ^/articles /index2.php?page=articleindex
RewriteRule ^/products /index2.php?page=displaycats
RewriteRule ^/service /index2.php?page=service
RewriteRule ^/myaccount /index2.php?page=myaccount

 

jdMorgan




msg:3235311
 1:26 am on Jan 29, 2007 (gmt 0)

Remember that .htaccess is a per-directory context. One of the things that this implies is that rule in .htaccess need have no knowledge of the 'higher-level' server directory and URL structure in order to work; This both protects the server security and makes it easier for you to write rules in the restricted .htaccess environment.

In practical terms, what this means is that the path to the current directory is stripped from the URL-path examined by RewriteRule. So, if you are in the top-level Web-accessible directory, then the path to the current directory, namely "/", is stripped.

Your rules will likely work better and more efficiently if tweaked as follows:

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^products/([0-9]+) /index2.php?crn=$1 [L]
RewriteRule ^articles/([0-9]+) /index2.php?article=$1 [L]
RewriteRule ^articles /index2.php?page=articleindex [L]
RewriteRule ^products /index2.php?page=displaycats [L]
RewriteRule ^service /index2.php?page=service [L]
RewriteRule ^myaccount /index2.php?page=myaccount [L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

ddregallo




msg:3235396
 3:45 am on Jan 29, 2007 (gmt 0)

Thanks jdMorgan, that was a big help. It is working as it should now.

</dan>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved