1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP | htaccess ReWrite URL | GET Variables

Discussion in 'PHP' started by webwizzy, Apr 23, 2012.

  1. #1
    Hi,

    I have a form at dns.html that submits to dns.php.
    The dns.html file consists of this.

    <form name="dnscheck" action="dns.php" method="get"><input type="text" name="domain"><input type="submit" name="submit" value="GO"></form>
    HTML:
    Hence, on form submission, the URL on the next page looks like this.
    http://localhost/dns.php?domain=mydomain.com&submit=GO
    Code (markup):
    I want the above URL to be re-written as below.

    http://localhost/dns/mydomain.com/
    Code (markup):
    Once re-written, I hope if somebody directly visits the above re-written URL, he would be taken to the content of the original URL?
    I have been trying to figure this out for hours, but no go. Would really appreciate any help on this.

    Thanks
     
    webwizzy, Apr 23, 2012 IP
  2. tech2006

    tech2006 Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've had similar issues I suggest you take a look at this post seeing that I can't postlinks i'll repost the document.

    In this post, I’ve given five useful examples of URL rewriting using .htacess. If you don’t know something about url rewriting then please check my older post about url rewriting using .htaccess.


    Now let’s look at the examples

    1)Rewriting product.php?id=12 to product-12.html

    It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.

    RewriteEngine on
    RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

    2) Rewriting product.php?id=12 to product/ipod-nano/12.html

    SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.

    RewriteEngine on
    RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2

    3) Redirecting non www URL to www URL

    If you type yahoo.com in browser it will be redirected to www . yahoo. com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
    RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]

    4) Rewriting yoursite . com/ user.php?username=xyz to yoursite . com /xyz

    Have you checked zorpia. com.If you type http :// zorpia. com/ roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http:/ /yoursite.com/xyz to http :// yoursite.com /user.php? username=xyz then you can add the following code to the .htaccess file.

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

    5) Redirecting the domain to a new subfolder of inside public_html.

    Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www . test .com point out to the files inside “new” folder.


    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.test\.com$
    RewriteCond %{REQUEST_URI} !^/new/
    RewriteRule (.*) /new/$1

    Popularity: 69% [?]
     
    tech2006, Apr 23, 2012 IP
  3. webwizzy

    webwizzy Active Member

    Messages:
    511
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    85
    #3
    Thanks for your post tech. However, none of those resolves my query here. Before asking here, I have already tried a number of options by googling, looking over at forums and stuff. I at least figured that for GET variables its something different and a [QSA] needs to be appended, however, that doesn't help me much either. It just doesn't re-write the way I want it to as mentioned in the first post, no matter what I do. Any help is much appreciated.
     
    webwizzy, Apr 23, 2012 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,148
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    ads2help, Apr 26, 2012 IP
  5. e-abi

    e-abi Member

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    38
    #5
    In theory this should work:
    
    RewriteEngine on
    RewriteRule ^dns/([0-9a-zA-Z\-\.]+)/$ dns.php?domain=$1&submit=GO
    PHP:
    If it does not, then try replacing / with \/

    
    http://localhost/dns/mydomain.com/
    
    
    
    http://localhost/dns.php?domain=mydomain.com&submit=GO
    
    PHP:
     
    Last edited: Apr 26, 2012
    e-abi, Apr 26, 2012 IP