Jump to content


Photo

explain this mod rewrite in .htaccess


  • Please log in to reply
3 replies to this topic

#1 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 16 June 2006 - 09:51 PM

Dear Freaks like me

I have to understand the following

RewriteRule listing/(.+) /listing.php?type=$1
this is in the .htaccess file.

I think it means if the url has listing/ then replace with /listing.php?type=$1

does the $1 get converted to the value (.+)

This is a crazy useful language to me.

Thanks
mojito

#2 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 17 June 2006 - 08:52 PM

Regular Expressions (RegEx).

This is simple to understand. The rule works like this. A url that someone types in like so:

[a href=\"http://www.site.com/listing/700\" target=\"_blank\"]http://www.site.com/listing/700[/a]

will actually point to:

[a href=\"http://www.site.com/listing.php?type=$1\" target=\"_blank\"]http://www.site.com/listing.php?type=$1[/a]

The best part about it is it is Spider Friendly, easy to remember, and when a user points to the first url they will always see it but the webserver will see the second url.

#3 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 19 June 2006 - 02:18 PM

[!--quoteo(post=385090:date=Jun 17 2006, 08:52 PM:name=steelmanronald06)--][div class=\'quotetop\']QUOTE(steelmanronald06 @ Jun 17 2006, 08:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Regular Expressions (RegEx).

This is simple to understand. The rule works like this. A url that someone types in like so:

[a href=\"http://www.site.com/listing/700\" target=\"_blank\"]http://www.site.com/listing/700[/a]

will actually point to:

[a href=\"http://www.site.com/listing.php?type=$1\" target=\"_blank\"]http://www.site.com/listing.php?type=$1[/a]

The best part about it is it is Spider Friendly, easy to remember, and when a user points to the first url they will always see it but the webserver will see the second url.
[/quote]

Sorry I should have made it clearer, I know the point and theory behind mod rewrite, i just dont understand the rules, are you saying they use regular expressions? I will check on that in any case. The $1 actually gets converted to some value given by the url. This is what is confusing me.
Thanks
mojito


#4 steelmanronald06

steelmanronald06
  • Staff Alumni
  • Advanced Member
  • 2,004 posts
  • LocationOk

Posted 20 June 2006 - 03:03 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]RewriteRule listing/(.+) /listing.php?type=$1 [/quote]

Lets see if I can break it down a bit more for you.

listing/(.+)    /listing.php?type=$1

That is mostly Regular Expressions (Regex). Notice I put a space in between. That is two sets of Regex.

listing/(.+)

That first part will represent a url like so: [a href=\"http://www.site.com/listing/700\" target=\"_blank\"]http://www.site.com/listing/700[/a]

/listing.php?type=$1

That second part is what the url is converted to.

[a href=\"http://www.site.com\" target=\"_blank\"]http://www.site.com[/a] stays the same. /listing/ turns into listing.php. because the 700 is in the place of where the (.+) is in the .htaccess, it gets inserted where the $1 is. Everything else is filled in so you get the url:

[a href=\"http://www.site.com/listing.php?type=700\" target=\"_blank\"]http://www.site.com/listing.php?type=700[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users