阿帕奇presenting虚拟子目录和参数传递到PHP脚本 [英] Apache presenting virtual subdirectories and passing parameters to PHP script
问题描述
我的根目录下包含一个选择的PHP文件:index.php文件,about.php等每一种可以采取一个ID参数自定义几个页面上的变量,如联络电话号码,电子邮件地址等
My root directory contains a selection of PHP files: index.php, about.php etc. Each of these can take an ID parameter to customize a few of the variables on the page, such as contact phone number, email address etc.
如果访问者是访问 HTTP:// MYSERVER / joebloggs (joebloggs作为一个参数,而不是一个子目录)我希望他们送达了从根目录下的index.php页面,但joebloggs要传递到index.php作为ID和页面进行自定义。我不希望有创建为每个用户ID的子目录,我宁愿保持在DB此信息,并让PHP产生的页面我。
If a visitor was to access http://myserver/joebloggs (joebloggs being a parameter, not a subdirectory), I want them to be served up with the index.php page from the root directory, but for joebloggs to be passed to index.php as the ID and the page then customized. I don't want to have to create a subdirectory for every user ID, I'd rather maintain this info in a DB and have PHP generate the pages for me.
此外,当用户再导航到about.php页,我想待结转这个ID,然后有大约过定制页面,即链接到关于保持在URL中ID参数: HTTP:// MYSERVER / joebloggs /约/
Furthermore, when the user then navigates to the about.php page, I would like this ID to be carried over and then have the about page customized too, i.e. a link to 'about' maintains the ID parameter in the URL: http://myserver/joebloggs/about/
我有我的心里是怎么做到这一点,上了mod_rewrite已经阅读了,但一个粗略的想法还没有多少运气在拼凑不同的解决方案一起。
I've got a rough idea in my mind how to do this and have been reading up on mod_rewrite but haven't had much luck in piecing various solutions together.
任何指针或帮助将非常AP preciated。
Any pointers or help would be much appreciated.
推荐答案
尝试是这样的:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \/(.+?)\/about
RewriteRule . /about.php?p1=%1 [L]
RewriteCond %{REQUEST_URI} \/.*?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)$ /index.php?p1=$1 [L]
应该做的工作。测试它在我的服务器上。
Should do the job. Tested it on my server.
这篇关于阿帕奇presenting虚拟子目录和参数传递到PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!