Query URL problem?

GT9

Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    මචංලා ‍ගොඩක් වෙබ් සයිට් වල දැන් query urls තියෙනවනේ. ඒ ගොඩක් ඒවල root index file එකෙන් හෝ වෙනත් file එකකින් query urls generate වෙනව වෙන්න පුලුවන්.

    උදා

    example.com/index.php?name=ranuka&age=19
    example.com/checkout.php?item=25

    ඔය වගේ.

    ‍මේ රූපෙත් බලන්න

    OSW1j8X.jpg



    ගොඩක් සයිට් වල query url's generate වෙන file එකේ extension එක මොකක්ද කියල දකින්න පුලුවන්, ගොඩක් ඒවල .php දකින්න පුලුවන්.

    උදා

    https://www.facebook.com/photo.php?fbid=1020356549656259674

    මේකේ .php කියල තියෙනවා. අැත්තටම extension එකේ ගැටලුවක් නෑ .rb, .py ඔය මොකක් උනත් කමක් නෑ

    ඒත් සමහර සයිට් වල මේ වගේ තියෙන්නේ

    OSW1j8X.jpg


    මෙහෙම කරල තියෙන්නේ හිතා මතාම file extension එක හංගලද? නැත්නම් වෙන මොකක් හරි technology එකක්ද? :dull::oo:

    සීනියර් වෙබ් ඩෙව්ස්ලා මේක ගැන මොකද කියන්නේ? :P
     

    galleline

    Well-known member
  • Feb 8, 2009
    6,088
    179
    63
    ********
    Just add .htaccess file to the root folder of your site(for example, /home/domains/domain.com/htdocs/) with following content:

    PHP:
    RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php
    First, verify that the mod_rewrite module is installed. Then, be careful to understand how it works, many people get it backwards.
    You don't hide urls or extensions. What you do is create a NEW url that directs to the old one, for example
    The URL to put on your web site will be yoursite.com/play?m=asdf
    or better yet
    yoursite.com/asdf
    Even though the directory asdf doesn't exist. Then with mod_rewrite installed you put this in .htaccess. Basically it says, if the requested URL is NOT a file and is NOT a directory, direct it to my script:



    PHP:
    RewriteEngine On  RewriteCond %{REQUEST_FILENAME} !-f  RewriteCond %{REQUEST_FILENAME} !-d  RewriteRule ^(.*)$ /play.php [L]
    Almost done - now you just have to write some stuff into your PHP script to parse out the new URL. You want to do this so that the OLD ones work too - what you do is maintain a system by which the variable is always exactly the same OR create a database table that correlates the "SEO friendly URL" with the product id. An example might be
    /Some-Cool-Video (which equals product ID asdf)
    The advantage to this? Search engines will index the keywords "Some Cool Video." asdf? Who's going to search for that?
    I can't give you specifics of how to program this, but take the query string, strip off the end



    PHP:
    yoursite.com/Some-Cool-Video
    turns into "asdf"
    Then set the m variable to this
    m=asdf
    So both URL's will still go to the same product




    yoursite.com/play.php?m=asdf yoursite.com/Some-Cool-Video

    mod_rewrite can do lots of other important stuff too, Google for it and get it activated on your server (it's probably already installed.)

    You have different choices. One on them is creating a folder named "profile" and rename your "profile.php" to "default.php" and put it into "profile" folder. and you can give orders to this page in this way:
    Old page: http://something.com/profile.php?id=a&abc=1
    New page: http://something.com/profile/?id=a&abc=1
    If you are not satisfied leave a comment for complicated methods.
     
    Last edited:
    • Like
    Reactions: GT9

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    Just add .htaccess file to the root folder of your site(for example, /home/domains/domain.com/htdocs/) with following content:

    PHP:
    RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php
    First, verify that the mod_rewrite module is installed. Then, be careful to understand how it works, many people get it backwards.
    You don't hide urls or extensions. What you do is create a NEW url that directs to the old one, for example
    The URL to put on your web site will be yoursite.com/play?m=asdf
    or better yet
    yoursite.com/asdf
    Even though the directory asdf doesn't exist. Then with mod_rewrite installed you put this in .htaccess. Basically it says, if the requested URL is NOT a file and is NOT a directory, direct it to my script:



    PHP:
    RewriteEngine On  RewriteCond %{REQUEST_FILENAME} !-f  RewriteCond %{REQUEST_FILENAME} !-d  RewriteRule ^(.*)$ /play.php [L]
    Almost done - now you just have to write some stuff into your PHP script to parse out the new URL. You want to do this so that the OLD ones work too - what you do is maintain a system by which the variable is always exactly the same OR create a database table that correlates the "SEO friendly URL" with the product id. An example might be
    /Some-Cool-Video (which equals product ID asdf)
    The advantage to this? Search engines will index the keywords "Some Cool Video." asdf? Who's going to search for that?
    I can't give you specifics of how to program this, but take the query string, strip off the end



    PHP:
    yoursite.com/Some-Cool-Video
    turns into "asdf"
    Then set the m variable to this
    m=asdf
    So both URL's will still go to the same product




    yoursite.com/play.php?m=asdf yoursite.com/Some-Cool-Video

    mod_rewrite can do lots of other important stuff too, Google for it and get it activated on your server (it's probably already installed.)

    You have different choices. One on them is creating a folder named "profile" and rename your "profile.php" to "default.php" and put it into "profile" folder. and you can give orders to this page in this way:
    Old page: http://something.com/profile.php?id=a&abc=1
    New page: http://something.com/profile/?id=a&abc=1
    If you are not satisfied leave a comment for complicated methods.

    ඒ කියන්නේ mod rewriting වලින්ම තමයි මේකත් කරන්නනේ. මම බැලුවේ වෙන මොකක් හරි ටෙක්නොලජි එකක්ද කියල. තෑන්ක්ස් මචෝ...:)
     

    galleline

    Well-known member
  • Feb 8, 2009
    6,088
    179
    63
    ********
    ඒ කියන්නේ mod rewriting වලින්ම තමයි මේකත් කරන්නනේ. මම බැලුවේ වෙන මොකක් හරි ටෙක්නොලජි එකක්ද කියල. තෑන්ක්ස් මචෝ...:)

    Ur welcome !!
     

    La Singnore

    Active member
  • Oct 16, 2013
    514
    159
    43
    කෙහෙල්බද්දර
    Just add .htaccess file to the root folder of your site(for example, /home/domains/domain.com/htdocs/) with following content:

    PHP:
    RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php
    First, verify that the mod_rewrite module is installed. Then, be careful to understand how it works, many people get it backwards.
    You don't hide urls or extensions. What you do is create a NEW url that directs to the old one, for example
    The URL to put on your web site will be yoursite.com/play?m=asdf
    or better yet
    yoursite.com/asdf
    Even though the directory asdf doesn't exist. Then with mod_rewrite installed you put this in .htaccess. Basically it says, if the requested URL is NOT a file and is NOT a directory, direct it to my script:



    PHP:
    RewriteEngine On  RewriteCond %{REQUEST_FILENAME} !-f  RewriteCond %{REQUEST_FILENAME} !-d  RewriteRule ^(.*)$ /play.php [L]
    Almost done - now you just have to write some stuff into your PHP script to parse out the new URL. You want to do this so that the OLD ones work too - what you do is maintain a system by which the variable is always exactly the same OR create a database table that correlates the "SEO friendly URL" with the product id. An example might be
    /Some-Cool-Video (which equals product ID asdf)
    The advantage to this? Search engines will index the keywords "Some Cool Video." asdf? Who's going to search for that?
    I can't give you specifics of how to program this, but take the query string, strip off the end



    PHP:
    yoursite.com/Some-Cool-Video
    turns into "asdf"
    Then set the m variable to this
    m=asdf
    So both URL's will still go to the same product




    yoursite.com/play.php?m=asdf yoursite.com/Some-Cool-Video

    mod_rewrite can do lots of other important stuff too, Google for it and get it activated on your server (it's probably already installed.)

    You have different choices. One on them is creating a folder named "profile" and rename your "profile.php" to "default.php" and put it into "profile" folder. and you can give orders to this page in this way:
    Old page: http://something.com/profile.php?id=a&abc=1
    New page: http://something.com/profile/?id=a&abc=1
    If you are not satisfied leave a comment for complicated methods.

    :yes::yes::yes: