SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite question

    I would like to send all users from
    www.domainname.com/cars/post-title into post.php?category=car&url=post-title
    AND
    all users from
    www.domainname.com/blog-title to blog.php?url=blog-title
    I wrote in htaccess the following lines:
    1. RewriteRule ^cars/?([-a-zA-Z_&0-9&,!]+).html$ post.php?category=car&url=$1
    2. RewriteRule ^/?([-a-zA-Z_&0-9&,!]+).html$ blog.php?id=$1

    The problem is if user type www.domainname.com/cars-some-text it sends to post.php and not blog.php because it take the first rule even if there is no "/" after "cars". Please tell me how I can write that it sends to cars/ only if there is also "/" in cars/ and not only "cars".

  2. #2
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by meee View Post
    I would like to send all users from
    www.domainname.com/cars/post-title into post.php?category=car&url=post-title
    AND
    all users from
    www.domainname.com/blog-title to blog.php?url=blog-title
    May I ask you why you are trying to make your URL's worse?
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why worse? It is easier to remember www.domainname.com/cars/my-new-car than http://www.domainname.com/post.php?c...url=my-new-car. I have user blogs on the site and than I have posts inside categories which is not related to blog. All work is already done so I don't think I will change all structure if not really necessary.

    Please go back to my question how to put condition that there need to be also / after cars to send user.

  4. #4
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by meee View Post
    why worse? It is easier to remember www.domainname.com/cars/my-new-car than http://www.domainname.com/post.php?c...url=my-new-car. I have user blogs on the site and than I have posts inside categories which is not related to blog. All work is already done so I don't think I will change all structure if not really necessary.

    Please go back to my question how to put condition that there need to be also / after cars to send user.
    The way you worded it in the original post made it sound like you wanted to change www.domainname.com/cars/my-new-car to http://www.domainname.com/post.php?c...url=my-new-car

    I would love to help you out but htaccess is Chinese to me
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried dobule /, so RewriteRule ^cars//?([-a-zA-Z_&0-9&,!]+).html$ post.php?category=car&url=$1 and it works. I am not sure why, but it works!

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem was in ? because question mark means that a character before is not a condition. Now I removed ? and it works perfectly.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •