Possible Duplicate:
.htacces to create friendly URLs. Help needed
I would like to have create a website, which loads up content from a MySQL database via PHP, while still being optimized for search engines.
I have considered a few approaches and was looking for some advice on which way would the best.
Users on my website would fill out a form and submit it, which gets saved in the SQL database. I would like to have it so that each new page could be accessed like this:
- domain.com/plugins/whatever
- domain.com/plugins/anotherpagename
Some approaches:
1.
A script generates a static HTML page in the plugins folder when the form is submitted. When the page is edited (there will be a edit button), the HTML page gets overwritten with the updated information.
- domain.com/plugins/whatever and domain.com/plugins/anotherpagename would all redirect to a PHP script.
However, I do not know how to create a .htaccess which would allow the PHP script to get the page name so that it can search the SQL database and bring up the correct information.
I am also unsure about how search engines would treat these pages?
- Maybe someone else can come up with an even better approach for this?
Thank you in advance for your help.
You have a few options for how to do this. The simplest way that matches your requirements would be to add the following to your .htaccess file:
The above pass all requests to
/plugins/anythingto yourscript.php, from which you can access the plugin name using$_GET['plugin'].If “plugins” is simply an example, and you want to be able to use
/anything/anything– then you may wish to look at passing all requests to your PHP script, and then parsing the requested URL.To do that, you’d use something like this in your .htaccess file:
To break that down, the above tells Apache to rewrite all requests where the file does not exist (i.e. images/css/js, etc.) to yourscript.php.
From there, you can access the whole URL via
$_SERVER['REQUEST_URI']. Which you can break down with string functions, regular expressions, and so on.