Serious issue in URL rewriting

Discussion in 'Apache' started by sajjad27s, Aug 20, 2008.

  1. #1
    Hi

    I need to implement a rewrite rule like this.

    If user enters this:

    http://www.mywebsite.com/anydomain.com

    then I need this URL to rewrite in

    http://www.mywebsite.com/mypage.php?d=anydomain.com


    (NOTE: anydomain.com can be any domain name or any tld.)


    Thanks.
     
    sajjad27s, Aug 20, 2008 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    Maybe something like this:

    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^([^/]+).com$ /mypage.php?d=$1.com [L]
    RewriteRule ^([^/]+).net$ /mypage.php?d=$1.net [L]
    RewriteRule ^([^/]+).org$ /mypage.php?d=$1.org [L]
    RewriteRule ^([^/]+).biz$ /mypage.php?d=$1.biz [L]
    RewriteRule ^([^/]+).info$ /mypage.php?d=$1.info [L]
    RewriteRule ^([^/]+).mob$ /mypage.php?d=$1.mob [L]
    
    Code (markup):
    You probably get the pattern from there? You will need to repeat that line for each domain name TLD, since ^([^/]+).([^/]+)$ could do a nasty stuff on your domain name, preventing visitors from accessing index.html for example, or any other file in your root html folder.
     
    pr0t0n, Aug 20, 2008 IP
  3. sajjad27s

    sajjad27s Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks but

    I have added the similar rules but its not working like

    RewriteRule ^([^/]+).com$ /mypage.php?d=$1.com [L]

    if I replace mypage.php with some thing else then it shows the Not Found error page. But if I use mypage.php as in the rule, it just goes on and on until I hit Esc.


    Please assist.
     
    sajjad27s, Aug 20, 2008 IP
  4. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #4
    Hmm odd. Does it work fine if you manually try to open it via yourdomain.com/mypage.php?d=blahblah.com ? Rewrite rule looks fine.. it must be something else then...
     
    pr0t0n, Aug 22, 2008 IP
  5. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #5
    Follow these 2 steps...

    1. First change the directory index page from index.htm to mypage.php.
    Place this line on top of .htaccess

    2. Once this is done, you can do queries like

    without rewriting the URL.
     
    olddocks, Aug 24, 2008 IP
  6. sajjad27s

    sajjad27s Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks olddocks. But you have given the alternate solution. I dont want to put /?d= in the URL. Please check the URL http://whois.domaintools.com/yahoo.com. I want to do the same functionality.

    And secondly I have an index.html as well on the site. So I cannot use this kind of thing.
     
    sajjad27s, Aug 24, 2008 IP