Another URL rewrite question

Discussion in 'Apache' started by Krnl, Sep 24, 2013.

  1. #1
    I'm trying to rewrite the following URL, and the rewrite seems to work, but doesn;t forward to the rewritten page.

    From: domain.com/index.php?random
    To: domain.com/random

    
    RewriteRule ^random$ /index.php?random [L]
    
    Code (markup):
    With this rewrite in place, I can visit both the From and To URL. I want the From URL to automatically redirect to the To domain (i.e., a user will never see index.php?random in their browser location).

    What am I doing wrong here?
     
    Krnl, Sep 24, 2013 IP
  2. BreezeHost

    BreezeHost Member

    Messages:
    139
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    28
    #2
    Please try :
    Redirect 301 /index.php?random http://www.domain.com/random
     
    BreezeHost, Oct 3, 2013 IP
  3. MBDungo

    MBDungo Active Member

    Messages:
    163
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    58
    #3
    This will solved your problem overly:
    RewriteEngine on
    
    RewriteRule ^/?([^/]+)$ /index.php?$1 [L]
    
    RewriteCond %{QUERY_STRING} !\=
    RewriteCond %{QUERY_STRING} ^(.+)$
    RewriteRule ^/?index.php$ /%1 [R,L]
    Code (markup):
    This will work even on "/index.php?anything" or "/index.php?whatever".
     
    MBDungo, Oct 7, 2013 IP