Jump to content

Archived

This topic is now archived and is closed to further replies.

mojito

explain this mod rewrite in .htaccess

Recommended Posts

Dear Freaks like me

I 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=$1

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

This is a crazy useful language to me.

Thanks
mojito

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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.
Thanks
mojito

Share this post


Link to post
Share on other sites
[!--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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.