signature16 Posted October 25, 2007 Share Posted October 25, 2007 I've been trying to make my URLs friendly, but it never seems to work correctly. This is the code I'm using on my index page: <?php $id = $_REQUEST['id']; if($id == "") { $id = "index"; } include "pages/$id.php"; ?> It creates links that look like this: www.website.com/index.php?id=random-webpage How can I convert those links into: www.website.com/random-webpage.php Quote Link to comment https://forums.phpfreaks.com/topic/74796-htaccess/ Share on other sites More sharing options...
premiso Posted October 25, 2007 Share Posted October 25, 2007 Always fun. You need some type of filter, but for the most part any request needs to be ported through a processing file. In this file I would do a check to see if the random-webpage.php exists. If it does than you send the user to that page if not, than it is a fake and you split up the file name and pass it to the correct location using the include as you have shown. It is more complicated than explained, but that is the gist of it. Quote Link to comment https://forums.phpfreaks.com/topic/74796-htaccess/#findComment-378172 Share on other sites More sharing options...
signature16 Posted October 25, 2007 Author Share Posted October 25, 2007 Hmm, could you post an example of the code I would need to use or point me to a place I could find an example? Quote Link to comment https://forums.phpfreaks.com/topic/74796-htaccess/#findComment-378177 Share on other sites More sharing options...
BlueSkyIS Posted October 25, 2007 Share Posted October 25, 2007 something like this in .htaccess: RewriteEngine On RewriteRule ^random-webpage\.php$ /index.php?id=random-webpage [L,NC] or if you will pass through ALL urls, something more like this (neither of these tested): RewriteEngine On RewriteRule ^(!index\.php)$ /index.php?id=$1 [L,NC] Quote Link to comment https://forums.phpfreaks.com/topic/74796-htaccess/#findComment-378178 Share on other sites More sharing options...
BlueSkyIS Posted October 25, 2007 Share Posted October 25, 2007 and if you want to send real pages to the browser without substitution, put this before all other rewrites: # Don't rewrite real files or directories after this point. RewriteCond %{SCRIPT_FILENAME} -f [OR] RewriteCond %{SCRIPT_FILENAME} -d RewriteRule .* - [L] so i guess this would be the whole thing: RewriteEngine On # Don't rewrite real files or directories after this point. RewriteCond %{SCRIPT_FILENAME} -f [OR] RewriteCond %{SCRIPT_FILENAME} -d RewriteRule .* - [L] RewriteRule ^(!index\.php)$ /index.php?id=$1 [L,NC] Quote Link to comment https://forums.phpfreaks.com/topic/74796-htaccess/#findComment-378180 Share on other sites More sharing options...
premiso Posted October 25, 2007 Share Posted October 25, 2007 I would post the code I used, but I have customized it so much there is too much to filter. That and I consider it proprietary information due to certain aspects of it. Anyhow a simple google search will provide you with more than enough information. http://www.google.com/search?hl=en&q=php+seo+friendly+url&btnG=Google+Search http://www.sitepoint.com/article/search-engine-friendly-urls http://techie-buzz.com/ask-techie/create-seo-friendly-urls-using-mod-rewrite-and-php-part-1.html A few different ways, which is best for you is for you to choose. Quote Link to comment https://forums.phpfreaks.com/topic/74796-htaccess/#findComment-378181 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.