Forum Moderators: phranque

Message Too Old, No Replies

htaccess weird behavior

         

joe2012

4:04 am on Jul 31, 2012 (gmt 0)

10+ Year Member



Hi,
I have some minor issue with htaccess codding. One of mode rewires probably conflicts with other rules but I cannot find out where . Any help would be appreciated. Doesn't matter where I put third line (marked as "Conflicting/not working code") it returns 404. Theoretically there is no conflict but something causes issues there.
Thanks!
RewriteEngine On
#Conflicting/not working code:
RewriteRule ^/pages/c/?([a-zA-Z0-9]+)?$ /pages/login/ccc.php?var=$1 [L,QSA]

#working fine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-_/\.]+)/info/?([a-zA-Z_\-]+)?(/|/*)?$ /pages/my_info_test.php?var=$1&mode=$2 [L,QSA]

#working fine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^/pages/*
RewriteCond %{REQUEST_URI} !^/pages/.*
RewriteRule ^([a-zA-Z0-9\-_/\.]+)$ /pages/my_test.php?var=$1 [L,QSA]

lucy24

6:23 am on Jul 31, 2012 (gmt 0)

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



Give us a hint. In English: What is the troublesome line supposed to do? It's no use saying "It doesn't go where I want it to". You have to explain where you do want it to go.

RewriteRule ^/pages/c/?([a-zA-Z0-9]+)?$

I am deeply suspicious of each of those question marks-- to say nothing of the ones in the two other Rules. When you Rewrite, you have to be very careful not to let multiple forms of the request all lead to a 200 valid page.

And what's the incoming query string that you're appending?

This package of rules needs a preceding redirect to deal with users who request the non-pretty form. Read the last week or so of threads in this forum.

[a-zA-Z0-9\-_/\.]+

You don't need to escape literal periods inside grouping brackets. But this is a pretty exhaustive list. What other characters could there be in your URL? In particular, allowing directory slashes on the same basis as everything else is, uh, kinda iffy.

g1smd

6:31 am on Jul 31, 2012 (gmt 0)

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



You do realise that the /* found in multiple places matches / or nothing or /////////////////// and that is a duplicate content nightmare waiting to happen?

The -d and -f checks are very very inefficient. If you are using the right URL structure and code the RegEx patterns correctly they can usually be removed. This is especially true when you use extensionless URLs correctly.

Trailing .* on a pattern is redundant and can be removed.

joe2012

1:30 pm on Jul 31, 2012 (gmt 0)

10+ Year Member



The idea behind this code is to create a website where username becomes a virtual homepage (beside physically existing pages on the server). Kind of www.domain.com/joe2012 and third condition takes care on it. The second condition describes sub directory of user homepage like www.domain.com/joe2012/info/user_profile or www.domain.com/joe2012/info/pictures ...etc
The first condition (and probably a few more) suppose to take care on user friendly urls using physical www.domain.com/pages/ directory.
Hopefully this information will be useful

g1smd

8:50 pm on Jul 31, 2012 (gmt 0)

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



I know what you're trying to do and while there is no single correct way to achieve what you want, there are a vast number of incorrect ways to attempt it. :) Many of those introduce duplicate content issues or unecessary redirection chains.

joe2012

9:37 pm on Jul 31, 2012 (gmt 0)

10+ Year Member



the issue has been resolved, thanks to everyone!