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

Apache Web Server Forum

    
.htaccess trouble
cmnetworx




msg:4234832
 9:25 am on Nov 25, 2010 (gmt 0)

I am trying very hard to understand how to properly use .htaccess files, and I have got most of it working, but I am stuck..

I am getting stuck particularly at the rewriting of the /companies part, The url would be something like /companies/?list=this and on the server side I want it to go to index.php?cat=this

However I know that my other rule
RewriteRule ^([0-9]+)/?$ index.php?cid=$1 [L]
is working against it, but I don't know how to fix it, or how to get the
RewriteRule ^companies/\?list=([A-Za-z_]+)?$ index.php?cat=$1 [L]
part to work with it.. Or if I even have that part working yet (haven't been able to test it yet)


Options +FollowSymLinks
RewriteEngine On

ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index.php?cid=$1 [L]

RewriteRule ^companies/\?list=([A-Za-z_]+)?$ index.php?cat=$1 [L]
RewriteRule ^([A-Za-z_]+)/?$ index.php?cat=$1 [L]


Open to any suggestions/help.
Also, I thought the "RewriteCond %{REQUEST_FILENAME} !-d" part would skip the rewrite if the directory actually exists. Did I do this wrong?

 

cmnetworx




msg:4235546
 6:52 am on Nov 27, 2010 (gmt 0)

I hate to bump this, but I am still stuck on this, Can anyone help me figure out where I am messing this up, My basic goal is

domain.com/1234 goes to index.php?bin=1234 (Works)
domain.com/abcd goes to index.php?cat=abcd (Works)
domain.com/companies/?list=this go to index.php?cat=this (Fails)

I have made many attempts, but I wonder if the
RewriteRule ^([A-Za-z_]+)/?$ index.php?cat=$1 [L]
is whats messing up the domain.com/companies/?list=this
request..

Currently this is what my .htaccess file looks like

Options +FollowSymLinks
RewriteEngine On

ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index.php?cid=$1 [L]
RewriteRule ^([A-Za-z_]+)/?$ index.php?cat=$1 [L]

#RewriteRule ^([companies]+)/([^/\.]+)/?$ /index.php?cat=$1&subcat=$2 [L]

RewriteCond %{REQUEST_URI} !^companies/
#rewriterule ^companies/(.*)$ /index.php?cat=$1 [L]
#rewriterule companies/(.*)/(.*)/$ /index.php?$1=$2 [L]
RewriteRule /companies//(.*)/(.*)/ index.php/?$1=$2 [L]

#RewriteRule ^companies/([^/\.]+)/?$ /index.php?cat=$1 [L]


I have tried the htaccess generator on this website also, still stuck.

Any ideas?

Thanks in advance.

cmnetworx




msg:4235547
 6:53 am on Nov 27, 2010 (gmt 0)

btw I have commented a few of those out, some are uncommented because I have tried about 30 variations trying to figure out what I'm doing wrong. Usually index.php is only passed cat=companies.

g1smd




msg:4235716
 7:12 pm on Nov 27, 2010 (gmt 0)

The ^([A-Za-z_]+)/?$ pattern is matching all requests so the final "companies" rules never get to see the request.

List those "more specific" companies rules before the "more general" ^([A-Za-z_]+)/?$ rule.

cmnetworx




msg:4235779
 12:02 am on Nov 28, 2010 (gmt 0)

Thanks for the reply.
I have changed the order, but I still think I have something odd in my rule or order..

Here is the updated htaccess

ErrorDocument 404 /404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^companies/
RewriteRule ^companies\/\?(.*)([A-Za-z]+) index.php?cpy=$1 [R=301,L,NC]

RewriteRule ^([0-9]+)/?$ index.php?cid=$1 [L]
RewriteRule ^([A-Za-z_]+)/?$ index.php?cat=$1 [L]



I think something is not right in the companies rule. I don't know alot about this but my guess is that its not seeing a match in the companies rule and going to the next rules where it is matching the ([A-Za-z_]+) rule..

Can anyone verify if I have this rule right?
RewriteRule ^companies\/\?(.*)([A-Za-z]+) index.php?cpy=$1 [R=301,L,NC]
I am trying to match it to domain.com/companies/?list=this

jdMorgan




msg:4237627
 10:59 pm on Dec 1, 2010 (gmt 0)

Without further details, and lacking useful comments in the original code, I'd suggest:

ErrorDocument 404 /404.php
#
Options +FollowSymLinks
RewriteEngine On
#
# Internally rewrite /companies/?list=xyz URL-path requests to /index.php?cat=xyz filepath
RewriteCond %{QUERY_STRING} ^list=([^&]+)$
RewriteRule ^companies/?$ /index.php?cat=%1
#
# Internally rewrite /<letters-and-underscores>/ URL-path requests to index.php?cat=<letters-and-underscores> filepath
RewriteRule ^([a-z_]+)/?$ /index.php?cat=$1 [NC,L]
#
# Internally rewrite /<numbers>/ URL-path requests to /index.php?cid=<numbers> filepath
RewriteRule ^([0-9]+)/?$ /index.php?cid=$1 [L]

Jim

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