jostclan Posted February 8, 2018 Share Posted February 8, 2018 I am beginning a version of our corporate website written with a in-house mySQL content database and PHP front end. I am looking at using pretty urls (site.org\pretty-page-url) instead of ugly urls (site.org\page.php?id=34). Without using Wordpress which I have no experience with is there a plugin or code I can use that can incorporate this feature? I can add any number of columns to my table to pull the pretty url value if that helps. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 8, 2018 Share Posted February 8, 2018 As long as you store "pretty-page-url" along with the page, and you guarantee that the value is unique across all pages, then it's easy. Apache? Probably. Stick this in your .htaccess or virtualhost configuration: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/?([^/]+)$ page.php?id=$1 [L]That uses mod_rewrite to do URL rewriting by taking any request that doesn't match an existing directory or file, and doesn't have any slashes in it, then sends it to page.php. Google "Apache URL rewriting" and spend a couple minutes reading through the results so you understand basically what it's all about. Then code up page.php so that it uses $_GET["id"] to find the right content. Obviously you can change the file and query string to something else if you want. Make sure your links on the site use the correct "/pretty-page-url" and not "/page.php?id=pretty-page-url" because those won't be changed automatically for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.