Jan Haha Jan Haha - 5 months ago 20
PHP Question

How to create sub pages with php on user request?

if my website url is like someUrl.com and a registered user whants to add an article to my website, I want to create a sub page with php:

Something like someUrl.com/someSubPage

So my question is: Should I create a new file on the server with php or should I save the data from the article in a database and generate the file everytime a user request it? And what about the url (someUrl.com/someSubPage) if I take the second choice? It is possible to still have an url for this?

Thank you in advance!:D

Edit:
Ok database seems to be the better way. But how about search engines and can I do this without a framework?

Answer

Yes, you can do it without a framework. But you might consider CodeIgniter, since it is very easy to install and learn, without a lot of weight. If you want to do it without: You have to create a .htaccess-file with the content:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]


# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

If the file is not found in the filesystem, the page index.php will be loaded. You can use $_SERVER['REQUEST_URI'] to get the requested page.

Comments