Forum Moderators: phranque

Message Too Old, No Replies

htaccess creating problem for the index page

domain name doesn't open the index page

         

phparion

9:21 am on May 11, 2007 (gmt 0)

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



Hi

I am using some rewrite rules e.g

ewriteCond %{REQUEST_URI} ^/.*$
RewriteRule ^([^.]+)/([^.]+)/([^.]+)\.html$ show_pages.php?page_url=$3&mode=subcatpage [L]

RewriteCond %{REQUEST_URI} ^/.*$
RewriteRule ^([^.]+)/([^.]+)/$ show_pages.php?sub_cat_name=$2&mode=subcatindex [L]

The rules are working fine however if I write

[http://][www.]example.com[/][index.php]

all matches of the above generates error because the rules are standing true

because i redirect URLs like

example.com/somevalue page.php?value=somevalue

therefore even in case of index.php it uses this rule to find the value...

How can I fix this problem so that if I write only my domain name or domain name and index.php with it it should only open the index.php page and no other page

thanks

jdMorgan

2:24 pm on May 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Several problems with that code... Incorrect patterns, unnecessary RewriteConds. To fix these, I'd suggest:

RewriteRule ^([^/]+)/([^/]+)/([^.]+)\.html$ show_pages.php?page_url=$3&mode=subcatpage [L]
#
RewriteRule ^([^/]+)/([^/]+)/$ show_pages.php?sub_cat_name=$2&mode=subcatindex [L]

I do not see that either rule will rewrite or redirect requests for index.php, so I cannot help with that problem. Is there another rule you did not show us?

Jim

phparion

5:12 pm on May 11, 2007 (gmt 0)

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



Hi Jim

thanks for your reply, in fact the problem was not htaccess but my php code I have fixed that code.

Can you please shed some light why your suggest rules are better for performance than mine? because my rules work but of course they must be improved.. just wanted to get the concept so that in future I can write more efficient rules

thanks

jdMorgan

7:15 pm on May 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the RewriteConds are not needed -- They will match any valid URL-path whatsoever.

And the RewriteRule patterns were incorrect, forcing the matching engine to try several times to find a match. To understand this, it is necessary to fully-understand the patterns that you used, and the patterns that I suggest; See the regular-expressions documentation cited in our forum charter [webmasterworld.com].

Jim

phparion

5:14 am on May 12, 2007 (gmt 0)

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



Thanks for the wise words Jim