Part of the EllisLab Network
   
 
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.
Posted: 11 July 2008 04:03 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  11-06-2006

I’m probably breaking all the rules of eticate again, but this isn’t really CI related, so I popped it in the lounge. I need someone to ‘teach me how to fish’ smile

I’m ( for the first time ) trying to get to grips with mod_rewrite. I’m hoping someone can offer some examples to get me going, and I can tweak them, but right now I’m at a brick wall. I think I’m ok with things like adding the www on the front and stuff, its just the more detailed rules I’m struggling with.

Heres what I want to do:
From the root, any number of letters or numbers followed by a slash and nothing else:

http://www.mysite.com/about/


Remove the slash and replace with a .php:

http://www.mysite.com/about.php


*Except don’t rewrite a specified one, leave as is:

http://www.mysite.com/contact/


A similar thing for the products folder:

http://www.mysite.com/products/satellite/


to

http://www.mysite.com/products/satellite.php

and finally:

http://www.mysite.com/products/satellite/rent/


to remove the end slash and swap with a .php, and replace /rent with -rent

http://www.mysite.com/products/satellite-rent.php

I’m not asking for someone to just do this for me (ok so maybe I am), but I think if I’ve got a couple of examples, I’ll be able to see how its done. I’ve got a load more rules to add for things like url parameters, but I want to have a bash at those, hopefully with the knowledge I’m gained from these ones…

Profile
 
 
Posted: 11 July 2008 06:06 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  11-06-2006

Ok I’m nearly there, the only one I’m stuck on now is this:

http://www.mysite.com/products/satellite/rent/

to remove the end slash and swap with a .php, and replace /rent with -rent

http://www.mysite.com/products/satellite-rent.php

Can anyone offer any tips?

Profile
 
 
Posted: 11 July 2008 08:53 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  11-06-2006

Ok I’ve sussed that one out now.

Profile
 
 
Posted: 12 July 2008 04:34 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  123
Joined  04-05-2007

Care to share how you did it, incase anyone else is interested in learning how to do it.

Profile
 
 
Posted: 16 July 2008 06:35 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  11-06-2006

Sorry bud I’ve done that thing haven’t I?

Yes of course I can share it:

This one turns this (if the last part of the url is ‘rent’ or ‘buy’):
http://www.mysite.com/products/satellite/rent/
into this:
http://www.mysite.com/products/satellite-rent.php

RewriteRule ^products/(.+)/(rent|buy)/$ /products/$1-$2.php [L]
RewriteRule ^products/(.+)/$ /products/$1.php [L]

and this one turns this:
http://www.mysite.com/products/satellite/
into this (if the folder is NOT ‘products’ or ‘contact’):
http://www.mysite.com/products/satellite.php
RewriteCond %{REQUEST_URI} !^/contact/$
RewriteCond %{REQUEST_URI} !^/products/.*$
RewriteRule ^(.*)/$ /$1\.php

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 62600 Total Logged-in Users: 21
Total Topics: 77073 Total Anonymous Users: 0
Total Replies: 416273 Total Guests: 164
Total Posts: 493346    
Members ( View Memberlist )
Newest Members:  eudj1nsehartEasyMLance SloanandrewjhscottShuvopatricovghazalravi_ghostblade_kaqfa