Need some help on MOD_Rewrite

Discussion in 'Apache' started by overdrive, Jul 8, 2007.

  1. #1
    Hello Everyone,

    I am trying to make my dynamic pages a little more se friendly and get the session Ids out of the urls. I have two instances that I need to be redirected

    Current URL:
    http://www.overdriveelectronics.com...ada91a5d521c82b&category=Portable+Electronics

    What I want:
    http://www.overdriveelectronics.com/review/category=Portable+Electronics

    Also,

    Current URL:
    http://www.overdriveelectronics.com/review/review_categories_yahoo_cats2.php?category=Car+Amplifiers

    What I want:
    http://www.overdriveelectronics.com/review/category=Car+Amplifiers

    Can anyone help me out with this? Thanks!

    If someone is really good at this and would like to earn a few extra bucks, please PM me and I will pay you to create my .htaccess file for this part of my site. Thanks!
     
    overdrive, Jul 8, 2007 IP
  2. VimF

    VimF Well-Known Member

    Messages:
    307
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #2
    Options FollowSymLinks
    RewriteEngine on
    RewriteRule ^review/category=([^/=]+)$ review/review_categories_yahoo_cats2.php?category=Portable+Electronics [L,NC]
     
    VimF, Jul 8, 2007 IP
  3. medicalhumor

    medicalhumor Peon

    Messages:
    1,393
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #3
    VimF
    I tried using the Mod_rewrite Generator on your site. Looks like an awesome tool. However it's not working for my case.

    I have a search form on my site, so users can search a database of business listings.

    The form is like this:
    Then it performs a search and spits out results, the url that it produces in the browser is:
    Using your generator, it gave me the following:
    Options FollowSymLinks
    RewriteEngine On
    RewriteRule ^search-([^/-]+)-([^/-]+)-([^/-]+)\.html$ search.php?q=$1&x=$2&y=$3& [L,NC]

    but when doing a search, the urls stay the same.

    Any advice as to what I'm doing wrong?
     
    medicalhumor, Jul 9, 2007 IP
  4. VimF

    VimF Well-Known Member

    Messages:
    307
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #4
    You still need to edit your php code, mod_rewrite is only the first part of the job.

    e.g. Add something like this into your search.php:
    
    if (preg_match('/\.php/i', basename($_SERVER['REQUEST_URI']))) {
    	header('HTTP/1.1 301 Moved Permanently');
    	header('Location: /search-'.preg_replace('/[^\w]+/', '', $q).'.html');
    	exit();
    }
    
    PHP:


    * Fixed an error in my previous post:
     
    VimF, Jul 9, 2007 IP
    medicalhumor likes this.
  5. medicalhumor

    medicalhumor Peon

    Messages:
    1,393
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #5
    VimF - that worked perfectly!!!!

    Thank you so much! GREEN REP given.




     
    medicalhumor, Jul 9, 2007 IP
  6. medicalhumor

    medicalhumor Peon

    Messages:
    1,393
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #6
    medicalhumor, Jul 9, 2007 IP