mojito Posted June 16, 2006 Share Posted June 16, 2006 Dear Freaks like meI have to understand the following[code]RewriteRule listing/(.+) /listing.php?type=$1[/code]this is in the .htaccess file.I think it means if the url has listing/ then replace with /listing.php?type=$1does the $1 get converted to the value (.+) This is a crazy useful language to me.Thanksmojito Link to comment https://forums.phpfreaks.com/topic/12199-explain-this-mod-rewrite-in-htaccess/ Share on other sites More sharing options...
steelmanronald06 Posted June 17, 2006 Share Posted June 17, 2006 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. Link to comment https://forums.phpfreaks.com/topic/12199-explain-this-mod-rewrite-in-htaccess/#findComment-46778 Share on other sites More sharing options...
mojito Posted June 19, 2006 Author Share Posted June 19, 2006 [!--quoteo(post=385090:date=Jun 17 2006, 08:52 PM:name=steelmanronald06)--][div class=\'quotetop\']QUOTE(steelmanronald06 @ Jun 17 2006, 08:52 PM) [snapback]385090[/snapback][/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.Thanksmojito Link to comment https://forums.phpfreaks.com/topic/12199-explain-this-mod-rewrite-in-htaccess/#findComment-47312 Share on other sites More sharing options...
steelmanronald06 Posted June 20, 2006 Share Posted June 20, 2006 [!--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.[code]listing/(.+) /listing.php?type=$1[/code]That is mostly Regular Expressions (Regex). Notice I put a space in between. That is two sets of Regex.[code]listing/(.+)[/code]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][code]/listing.php?type=$1[/code]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] Link to comment https://forums.phpfreaks.com/topic/12199-explain-this-mod-rewrite-in-htaccess/#findComment-47691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.