Forum Moderators: phranque

Message Too Old, No Replies

Problem with RewriteRule

Problem with RewriteRule

         

tic74

1:04 pm on Mar 24, 2009 (gmt 0)

10+ Year Member



Hi friends,I need to fix each page from my site for the providers,etc. so it connect to url with the names, instead the id=number, using friendly urls.
I use:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ bankingdetail.php?route=$1 [L,QSA]

Im using php and it worked fine checkink the route value.

Now I added :

RewriteRule ^(.*)$ paydaydetail.php?route=$1 [L,QSA]

But seems like it messed up the htaccess process.

I mean, by sample, www.mysite.com/paydaydetail.php?id=20, but he need redirect to www.mysite.com/MypaydayWorld
But it didn't worked...

I mean, it worked with the first page and the firs rule () not on the second rule (RewriteRule ^(.*)$ bankingdetail.php?route=$1 [L,QSA]) and i dont know what to do with the second rule. Maybe, i was thinking , we will need some general rule for all the pages,right? But I tried some lines and it didnt worked, please, let me know if you see some fix for this issue.
Thanks in advance!
Tic

jdMorgan

1:19 pm on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot add a second rule with the same pattern as the first; Any requested URL matching the pattern in the first rule will be rewritten to the script, and the second rule will never be applied.

In case it is not clear, RewriteRule works like this:
RewriteRule requested-URL --> substitution-URL-or-filepath.

Therefore in your first rule above, you are saying:


If the requested URL does not resolve to a physically-existing file
AND
If the requested URL does not resolve to a physically-existing directory
THEN
Rewrite all URL-path requests to bankingdetail.php and set the query string variable "route" equal to the requested URL-path.

Jim

tic74

1:56 pm on Mar 24, 2009 (gmt 0)

10+ Year Member



Thanks Jim! Great explanation.
Anyway, what do you think about add a general rule? I dont know very much about htaccess and regular expressions but something like:
RewriteRule ^(.*)$ ^(.*).php?route=$1 [L,QSA] .
A general rule can to work?

jdMorgan

2:21 pm on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That rule is invalid and cannot work. I strongly suggest that you review the documents cited in our Apache Forum Charter [webmasterworld.com] and look at the threads in our Apache Forum Library [webmasterworld.com] before continuing.

A bad rule --even one with a tiny error-- can be very dangerous to the operation and ranking of your Web site.

Jim

g1smd

6:11 pm on Mar 24, 2009 (gmt 0)

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



If you have two types of pages, then you need two different 'types' of URL which ModRewrite can tell the difference between.

This could be as simple as the first letter being different or the names being a fixed, but different, length.

tic74

8:36 pm on Mar 24, 2009 (gmt 0)

10+ Year Member



hi g1smd, thanks! sorry, can you show me a easy example? im not sure about the first letter thign that you told me, but seems a good idea.

thanks!

g1smd

9:20 pm on Mar 24, 2009 (gmt 0)

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



Sections and Pages like /0001 vs. /0000001 or perhaps /s00001 vs /p00001

tic74

5:16 pm on Mar 25, 2009 (gmt 0)

10+ Year Member



Sorry, g1smd, im not very expert on this stuff. do you mean change the kind of page where we load the route variable,something like this?:
RewriteRule ^(.*)$ ^(.*)s00001.php?route=$1 [L,QSA] .

thanks!

g1smd

5:26 pm on Mar 25, 2009 (gmt 0)

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



No. I mean use those simple URLs in the links on your pages so that those become the URL that people 'see' and 'use' to access your content.

Then set up a rewrite so that those URL formats pull the content from your dynamic parameter-driven script, without revealing the complexity of those parameters back to the user.

That is URLs with an 's' and some digits get routed to a different script than requests for some other URL format. The leading 's' in the URL identifies to Mod_Rewrite what to do with this URL request.

The leading letter would act as a URL filter. Instead of using (.*) to grab all URLs you would use the leading letter in the pattern so that only URLs that contain that letter will be affected by this rule. URLs with a different letter would be processed by a different rule.