I've got a question, and am not sure how in-depth this is... A buddy of mine told me there's a way to make a script that accepts input and looks like a directory structure... For example: /something/input1/ /something/input2/ Where input1 and input2 are not actual directories, but data being passed to /something/index.php I know you can pull this off with mod-rewrite, but am just wondering if it's also possible with PHP... Thanks
I see what you mean, you need to specify the parameters in a .htaccess file. But php alone can't do it, because server doesn't know that the link is symbolic.
it is possible - you can set via mod_rewrite to redirect any request that's not a filename to index.php RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] Code (markup): you can then query $_SERVER['DOCUMENT_URI'] or whatever to grab the address they typed and compare it against what you need... hth
This is probably the easiest code to use (allows variables): Edit: Just to let you know, you need to create a .htaccess with the code and upload it to the main directory. RewriteEngine on RewriteRule ^something/(.*)/?$ index.php?input=$1 Code (markup): The (.*) will become the variable $1 which will be passed to the php script using $_GET[]; If you want to use more than one variable, you can seperate them with another /, _ or anything else which wont be used in the variable. Example: RewriteEngine on RewriteRule ^something/(.*)/(.*)/?$ index.php?input=$1&anotherinput=$1 Code (markup): If you just want a simple redirect with variables, you can simple use: RewriteEngine on RewriteRule ^something somthing.php Code (markup): The above will redirect somthing/ to somthing.php I hope that helps! Regards
One of the most common rewrite rules for SEO friendly URLs RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 HTML: So RewriteCond %{REQUEST_FILENAME} !-d means don't apply RW rule if requested URL is directory and the seconds same but for file. RewriteRule ^(.*)$ index.php/$1 means anything you get in URI post-pend to index.php so URL: like http://www.example.com/index.php?module=news&year=2008&category=coding&id=45&page=2 Will be something like http://www.example.com/index.php/news/2008/coding/Optimizing-A-PHP-Code?page=2 and finally http://www.example.com/news/2008/coding/Optimizing-A-PHP-Code?page=2 so there is a great benefit for SEO , as to search engine id=45 doesn't mean anything but having Optimizing-A-PHP-Code does mean a lot and weights a lot