Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 05-04-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
  .htaccess construction problem

What I want to do may sound odd or strange way to do things but I have a reason for it and think it must be ralatively simple to do.

I can do simple .htaccess url rewrites (and to most what I need to do is probably simple) but I'm just struggling with how I want to construct it now.

I want the url to be constuctued as follows
mydomain.com/news/$date-$id
The date and id are stored seperately in the database and I want them connected with a "-" and not a "/" is that makes sence.

So the url will look something like
mydomain.com/news/050406-12

Anyone able to show me the correct way to get this right

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-04-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
I presume you want that URL mapped to a script that will accept the date and id as parameters? If that's correct, then assuming a script called news.php; your rule would look something like this:

Code:
RewriteRule ^news/(.*)-(.*) news.php?date=$1&id=$2 [L]
...should do the trick.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-04-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
Nice one dmorison, it works a treat.

What does the [L] in it for?

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-04-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
The L means "L"ast rule, which stops mod_rewrite from processing any further rules on the new URL.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 05-04-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
Have been having a think and now unsure if I want the "-" in there now.
I thougth it would have been a very simple removal of the "-" from the rewrite code to sort it but doesn't seem to be the case.

Can you show me my error again, please

Cheers
Wardy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-04-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
Yes, the "-" was crucial to how that regular expression matched the date and the id separately. By removing it; there is no longer a demarkation, so the first bracketed expressesion would have captured everything. My guess is that the whole thing would have be passed to your news script as the date variable.

To get around this; and as long as the date will always be 6 characters long, you can use a fixed length matching pattern to pick up the date; and the match the remainder as the ID; like this:

Code:
RewriteRule ^news/([.]{6})(.*) news.php?date=$1&id=$2 [L]
I think that should work....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-04-06
morleymouse's Avatar
Super Member
 
Join Date: Aug 2003
Location: Costa Del Sheffield
Posts: 2,752
Thanks: 3
Thanked 10 Times in 6 Posts
morleymouse is an unknown quantity at this point
another way around it is just have mydomain.com/news/050406-12

RewriteRule ^news/(.*) news.php?id=$1 [L]

then in the script

$info = explode("-", $id);

$info[0] = $date;
$info[1] = $id;


bit of a hack around, but works.


or use the better, clever solution provided above
__________________
Dan Morley
Alpharooms.com
daniel at alpharooms dot com - Hotels, Flights, Airport Transfers, Care Hire + More! sign up
My Blog | Cheap Holidays
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 05-04-06
Wardy's Avatar
This is the one
 
Join Date: Aug 2003
Posts: 2,747
Thanks: 14
Thanked 0 Times in 0 Posts
Wardy is an unknown quantity at this point
Quote:
Originally Posted by dmorison
Code:
RewriteRule ^news/([.]{6})(.*) news.php?date=$1&id=$2 [L]
I think that should work....
Doesn't seem to. Maybe I should go with the way it was before which was preferable, only reason I was lookign to change is because I have some old news articles that have been published and I don't want to much google up with creating new URLS and duplicating the same stories.

Cheers
Wardy
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 05-04-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
Hmmmm.. i'll look into that, in the mean time, as it's always going to be 6 characters you can just do this:

Code:
RewriteRule ^news/(......)(.*)$ news.php?date=$1&id=$2 [L]
...which I just tested quickly so should be ok this time
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 05-04-06
Super Moderator
 
Join Date: Aug 2003
Posts: 2,451
Thanks: 0
Thanked 0 Times in 0 Posts
Rich is an unknown quantity at this point
[.] will match just a full stop - the []'s stop it acting as a wildcard.

You could use: -
Code:
RewriteRule ^news/(.{6})(.*) news.php?date=$1&id=$2 [L]
or
Code:
RewriteRule ^news/([0-9]{6})([0-9]*) news.php?date=$1&id=$2 [L]
which limits it to only urls that contain numbers and can make your life easier if you later create any other urls under the news folder.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On