Search code examples
phpgetdynamic-pagesstatic-pages

Dynamic link to static link?


In stackoverflow, the page url is like How to store post variables value

But when we use php to create web pages, its most likely has a url like www,somewebsite.com/mypage?someid=123

And then the content is displayed.

I want to know how to convert www.somewebsite.com/mypage?someid=123

into www.somewebsite.com/mypage/some_page_link_here_which_is_static

Anybody Have idea how to do it? I tried searching this question first, but it showed me c/c++/java linking :|

Edit:

I tried some of youtube videos, My HTACESS code is
RewriteEngine on
RewriteCond %(REQUEST_URI) find/([0-9]+)/
RewriteRule find(.*)/ /find.php?id=$1

which will turn some url like
something/find.php?id=11 into
something/find/11

The .htaccess file is in root of my website.But it still fails. Have I done something wrong?


Solution

  • Many CMS and web programming frameworks support the implementation of such user (and search engine) friendly links.

    On the lowest level, you may use the URL Rewrite feature found on all servers.

    If you use Apache server, you have to edit the .htaccess file; for IIS (Windows server) the web.config file.

    Google for url rewrite apache or url rewrite IIS.

    Update: As an example, see this solution (borrowed from from CodeIgniter). You can of course replace index.php, images etc. with whatever you want.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    Update 2 - Explanation

    As for a more in-depth explanation, I've found this excellent introduction/tutorial on the topic: URL Rewriting for Beginners

    Hopefully this makes much more sense that the unexplained example above:)