Welcome to WebmasterWorld Guest from 54.158.143.40

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess trouble

   
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?
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.
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.
7:12 pm on Nov 27, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
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
10:59 pm on Dec 1, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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