Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 10-02-06
Stress Head's Avatar
Registered User
 
Join Date: Apr 2004
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Stress Head is an unknown quantity at this point
  Bloody Mod Rewrite!!

OK. Got my rewrite working sort of.

I have the following rule working fine

RewriteRule ^celeb/(.*).html$ celeb.php?Celeb=$1

This works fine if the name is Madonna. But if the name is Jennifer Lopez, then I get celeb/Jennifer%20Lopez.html in the URL.

How can I change the rule to replace the %20 with a -
__________________
Work like you don’t need to, Love like you’ve never been hurt, Dance like no one is watching.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-02-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
What apears in the URL is down to whatever is generating the URL - it happens before any re-write rules come into play.

In other words, there's nothing you can do in your .htaccess that will fix the %20; it has to be done wherever /celeb/Jenifer Lopez.html is being generated, which I guess would be in some other script on your site. If that's the case; then the other script needs to be responsible for doing a str_replace on " " with "-".
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-02-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
Spaces will always really get converted to either %20 or + by browsers or webservers as spaces in urls arn't valid.

The solution to your problem is just to link to celeb/Jennifer-Lopez.html that will then result into a local request of celeb.php?Celeb=Jennifer-Lopez.

Don't forget mod_rewite is only involved in getting from the html to the php so if you're getting celeb/Jennifer%20Lopez.html then its your php thats generating that (probably as the invalid 'celeb/Jennifer Lopez.html') and is not connected to the mod_rewrite rule.

So at the start of your php replace '-'s with spaces in your Celeb variable and before outputing any links replace spaces with '-'s .. then work out what to do with names with hyphens in them!

edit: hmm, guess I pretty much just wrote the same as dmorison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-02-06
Stress Head's Avatar
Registered User
 
Join Date: Apr 2004
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Stress Head is an unknown quantity at this point
  Wink

Thanks guys.

I did try the php echo str_replace(" ", "-", method and it works fine at changing the url to celeb/Jennifer-Lopez.html BUT as the record in the database is Jennifer Lopez NOT Jennifer-Lopez it returns an empty result.

I realise I could just replace all the spaces in the database records for - but I am trying to leave the data in it's original format, so that updating it doesn't have me spending hours doing find replace every time I want to update it. Long term idea being the updating is done automatically by a cron or something.

So is there a way to remove the - before running the query.

I'm a bit of a novice at php as you can no doubt tell
__________________
Work like you don’t need to, Love like you’ve never been hurt, Dance like no one is watching.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 10-02-06
Swiss's Avatar
memoryfinder.co.uk
 
Join Date: Jun 2005
Location: Wiltshire, UK
Posts: 343
Thanks: 0
Thanked 0 Times in 0 Posts
Swiss is an unknown quantity at this point
You do a str_replace(" ","-",$string) when creating your links, and then you do another str_replace, but in reverse before querying your database.
__________________
Kris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-02-06
NetNeo's Avatar
Web monkey
 
Join Date: May 2005
Location: Cambridgeshire
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
NetNeo is an unknown quantity at this point
I use this too, and Kris is correct.

To generate the page name use:
echo str_replace(" ","-",$Celeb) . ".html";

Then, in the file celeb.php use the following at the top of the page:
$Celeb = str_replace("-"," ",$_GET['Celeb']);

This would then work for you

(N.B. before I am flamed, this will work but I would recommend validating the passed variable correctly as the example above would live you open to hacking!!!!!)

I hope this clarifies it all a little better and puts all the replys into one answer. Good luck, stick at it as it works excellently if you can crack the mod_rewrite.

One of my sites has 4 physical pages yet has over 360,000 viewable pages all down to mod_rewrites
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 13-02-06
Stress Head's Avatar
Registered User
 
Join Date: Apr 2004
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Stress Head is an unknown quantity at this point
Thanks for the replies guys. As a bit of a php novice I couldn't figure out how to remove the - from the string before running the query. BUT thanks to NetNeo I have done it. Afraid I am using DW to write my php so deciphering it isn't easy.

Had to start learning to hand code first, but well worth it as it taught me quite a bit, along with how to fix this problem.

For anyone with the same problem, this is what I did for the link

<?php echo str_replace(" ", "-", $row_celebs['CELEB']); ?>.html">

Then in Jennifer-Lopez.html (for example) I added the bit in red

if (isset($_GET['Celeb'])) {
$colname_main_query = (get_magic_quotes_gpc()) ? str_replace("-"," ",$_GET['Celeb']) : addslashes($_GET['Celeb']);
}

Thanks again.
__________________
Work like you don’t need to, Love like you’ve never been hurt, Dance like no one is watching.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 13-02-06
redbird's Avatar
Registered User
 
Join Date: Jun 2005
Location: Worcester
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
redbird is an unknown quantity at this point
It isn't just the spaces you might have a problem with you might want to look at using urlencode and urldecode

This link will explain better than I can
http://uk.php.net/manual/en/function.urlencode.php
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mod Rewrite help stevenm The Affiliate Marketing Lounge 11 31-10-05 12:23 PM
mod rewrite in root only tezar Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 17 18-08-05 04:33 PM
Sub domains mod rewrite help wanted purple Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 0 03-05-05 01:23 PM
Mod rewrite andy_jacko Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 11 13-10-04 11:54 AM
Redirecting Clicks + Mod Rewrite Stress Head Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 1 12-06-04 04:29 PM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7