.htaccess I have been stuck all day

Discussion in 'Apache' started by L146705, Oct 22, 2006.

  1. #1
    hi,
    I have been trying to do my .htaccess all day the best I can get is this:
    to
    www.ebooklobby.com/details/51/Life%2520in%2520the%2520Red%2520Brigade/?id=51&title=Life%2520in%2520the%2520Red%2520Brigade
    Code (markup):
    I want to get rid of the ?id=51&title=Life%2520in%2520the%2520Red%2520Brigade on the end. On the link to the page I pass the id and title parameters is there a way to remove them from the end of the url. Also I want to get rid of the %2520 characters.

    The url I want is

    http://www.ebooklobby.com/ebook-title/
    Code (markup):
    Here is the code of the .htaccess file

    RewriteEngine on 
    # 
    # Internally rewrite search engine friendly static URL to dynamic filepath and query 
    RewriteRule /([^/]+)/([^/]+)/?$ /details.php?id=$1&title=$2 [L] 
    # 
    # Externally redirect client requests for old dynamic URLs to equivalent new static URLs 
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /details\.php\?id=([^&]+)&title=([^&]+)\ HTTP/ 
    RewriteRule ^details\.php$  [url]http://www.ebooklobby.com/details/%1/%2/[/url] [R=301,L]
    Code (markup):
     
    L146705, Oct 22, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Post an example of the original URL and how you want it. The number will have to be there some where.

    The %2520 part will have to be edited in the script.
     
    Nintendo, Oct 23, 2006 IP
  3. L146705

    L146705 Peon

    Messages:
    910
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for the reply
    original

    http://www.ebooklobby.com/details.php?id=8&title=The%20Sett%20And%20Weaving%20Of%20Tartans%20&catname=Art
    Code (markup):

    how I want it

    http://www.ebooklobby.com/art/The-Sett-And-Weaving-of-Tartans
    Code (markup):
     
    L146705, Oct 23, 2006 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    Nintendo, Oct 23, 2006 IP
  5. L146705

    L146705 Peon

    Messages:
    910
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks that seems to work, how do I get rid of the %20, is it a regular expresion?
     
    L146705, Oct 23, 2006 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    You have to edit the script so it doesn't have that in the link. That's a space in the URL. Like changing it to -.
     
    Nintendo, Oct 23, 2006 IP
    L146705 likes this.
  7. L146705

    L146705 Peon

    Messages:
    910
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #7
    the links are pulled from the database, it uses the title of the article as the link. I ain't too sure how I would edit the title to cater for the url. I was thinking of doing a regular expresion on it to replace the #20 with a -.
     
    L146705, Oct 23, 2006 IP
  8. L146705

    L146705 Peon

    Messages:
    910
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #8
    <?php
    $string = 'page title blah hasdhasd';
    $pattern = '/ /i';
    $replacement = '-';
    echo preg_replace($pattern, $replacement, $string);
    ?>
    I used code similar to the above to sort it out, thanks for your help.
     
    L146705, Oct 24, 2006 IP