SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist ColinHughes's Avatar
    Join Date
    Sep 2004
    Location
    Spain
    Posts
    473
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    redirect from base directory

    Hi

    I am having difficulty making this work, and I have tried hard over the past 24 hrs.

    I have http://localhost/my-property/?p=1 which I need to redirect to http://localhost/my-property/index.html?p=1.

    Simples!! Well not for me I am afraid.

    My ht_access file contains the following:

    HTML Code:
    Options +FollowSymLinks All -Indexes
    
    RewriteEngine on
    
    RewriteRule ^/p=([0-9]+)$   /my-property/index.html?p=$1 [L,R=301]
    
    RewriteRule index([0-9]+)\.html$  index.html [L,R=301]
    
    RewriteRule list-page([0-9]+)\.html$ /my-property/index.html?p=$1 [L,R=301]
    
    RewriteRule ^(.*)\.html $1.php [L]
    The first line is the one that is causing me grief, the others work just fine, andthis is the final attempt of many with and without a rewrite cond.

    I hope somebody can point out just where I am going wrong, I have trawled the pages of this site but still cannot find a solution.

    TIA

    Colin

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Hi Colin!

    I can see why the first line has a problem - and you should be able to see it, too! Because the RewriteRule can ONLY examine the {REQUEST_URI} string (which does NOT contain the {QUERY_STRING}), any attempt to access it (or the {HTTP_HOST} or other Apache variables) is doomed to failure.
    My ht_access file contains the following:
    Hmmm, that's the .htaccess file! No filename, just the htaccess file extension.
    Code:
    Options +FollowSymLinks All -Indexes
    
    RewriteEngine on
    
    RewriteRule ^/p=([0-9]+)$   /my-property/index.html?p=$1 [L,R=301]
    # the ^/ will ONLY match on an Apache 1.x server
    # p=(\d+) is obviously the query string
    # use RewriteCond %{QUERY_STRING} p=(\d+) to capture the numeric value of p
    # followed by RewriteRule index\.php$ my-property/index.html?p=%1 [R=301,L]
    
    RewriteRule index([0-9]+)\.html$  index.html [L,R=301]
    # Strips digits off index#.html
    
    RewriteRule list-page([0-9]+)\.html$ /my-property/index.html?p=$1 [L,R=301]
    # captures digits appended to list-page#.html and sends then as the
    # value of p to my-property/index.html in the new/replacement query
    # string
    
    RewriteRule ^(.*)\.html $1.php [L]
    # redirects EVERY .html file to its .php equivalent
    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •