www.webdeveloper.com
Results 1 to 3 of 3

Thread: mod_rewrite help needed

  1. #1
    Join Date
    Feb 2007
    Posts
    148

    mod_rewrite help needed

    Hi. I need some help with creating search engine friendly URLs. I know there is a lot of documentation but I am new to .htaccess and I just cannot wrap my head around it beyond the basics. I want to create different rules for different pages:

    site.com/index.php?p=XX to site.com/XX AND site.com/XX/
    site.com/browse.php to site.com/browse AND site.com/browse/
    site.com/browse.php?cat=XXX to site.com/browse/XXX and site.com/browse/XXX/
    site.com/profile.php?user=XX to site.com/user/XX and site.com/user/XX/
    site.com/view.php to site.com/view and site.com/view/

    the reason why I want the it to operate on both trailing slash and without is that people might sometimes enter the URL differently.

    finally, does anyone know the best way to rewrite a search query URL, seeing I have both a simple search (1 field) and an advanced search (multiple fields). How would the variables be fed into the URL?

    Thanks so much!

  2. #2
    Join Date
    Apr 2012
    Posts
    22
    If you want when you write site.com/XX to execute site.com/index.php?p=XX

    RewriteEngine On

    RewriteRule ^\/browse(\/)?$ /browse.php [NC]
    RewriteRule ^\/browse/(.*)(\/)?$ /browse.php?cat=$1 [NC]
    # And so on for the rest. The index can use this one
    RewriteRule ^\/(.*)$ /index.php?p=$1 [NC]

  3. #3
    Join Date
    Feb 2007
    Posts
    148
    I wrote it like this

    Code:
    RewriteEngine On
    
    RewriteRule ^\/browse(\/)?$ /browse.php [NC]
    RewriteRule ^\/browse/(.*)(\/)?$ /browse.php?cat=$1 [NC]
    
    RewriteRule ^\/(.*)$ /index.php?p=$1 [NC]
    
    RewriteRule ^\/view/(.*)(\/)?$ /view.php?id=$1 [NC]
    
    RewriteRule ^\/user/(.*)(\/)?$ /profile.php?user=$1 [NC]
    
    RewriteRule ^\/upload(\/)?$ /upload.php [NC]
    None of it works though...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles