web_master Posted August 12, 2014 Share Posted August 12, 2014 I use the links in php like this: index.php?content=filename So I want to use it in future like: http://example.com/2014/link-name/post-head-name/ I dont have the idea how can I do that? Can anybody help me how to do that in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/290417-forward-compatibility-link-mod_rewrite/ Share on other sites More sharing options...
requinix Posted August 12, 2014 Share Posted August 12, 2014 It's called URL rewriting, if you want to search around for information on that (of which there is a lot). You're using Apache I presume? Quote Link to comment https://forums.phpfreaks.com/topic/290417-forward-compatibility-link-mod_rewrite/#findComment-1487577 Share on other sites More sharing options...
mogosselin Posted August 12, 2014 Share Posted August 12, 2014 So, with Apache, you can use a file named .htaccess. You put that file in your directory where your PHP resides and this will gives Apache instructions. Apache is responsible for 'forwarding' your request to the PHP 'engine'. By default, all it will do is check the URL. If the filename ends with .php, it will try to tell PHP to execute that file. But, with mod_rewrite (an Apache module), you can configure apache to change the URLs. For example, you can tell it to rewrite URLs with a certain pattern to another. Here's a tutorial I found: http://www.sitepoint.com/apache-mod_rewrite-examples/ Here's one I wrote myself (you can give me your comments if you read it): http://www.mogosselin.com/friendly-url-for-php-with-apache/ If it doesn't work for you, you can query Google for 'php mod_rewrite tutorial' or 'php mod_rewrite example', etc. Quote Link to comment https://forums.phpfreaks.com/topic/290417-forward-compatibility-link-mod_rewrite/#findComment-1487599 Share on other sites More sharing options...
web_master Posted August 12, 2014 Author Share Posted August 12, 2014 I write in htaccess file next: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?route=$1 [QSA]</IfModule> in PHP file is: $route = explode("/", trim($_GET["route"], " \t\n\r\0\x0B/")); so how can I split those variables, to make links in php files? example domain.com/content/main/header-of-text/155 content is the content file which is included into index.php main is a some group of texts (name is stored in database - joined tables) header-of-text is a header of the text stored in database - just writed 155 is the ID of text without rewriting thats looks like domain.com?route=content&textgroup=7&id=155 ...or am a totaly wrong... Quote Link to comment https://forums.phpfreaks.com/topic/290417-forward-compatibility-link-mod_rewrite/#findComment-1487625 Share on other sites More sharing options...
Ch0cu3r Posted August 13, 2014 Share Posted August 13, 2014 so how can I split those variables, to make links in php files? list Quote Link to comment https://forums.phpfreaks.com/topic/290417-forward-compatibility-link-mod_rewrite/#findComment-1487700 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.