使用PHP& amp; htaccess漂亮的URL URL变量
希望有人可以在这里提供一些帮助。这是多层的问题。简而言之,我想拥有漂亮的URL,这些URL使用URL变量来访问文件夹中的文件。
hoping someone can offer some assistance here. This is an issue with multiple layers. In short, I want to have pretty URLs that use a URL variable to a file within a folder.
所以,我要 http ://www.example.com/?page = path / to / page 看起来像 http://www.example.com/path/to/page/
在index.php页面上,加载上述内容:
On the index.php page, to load the above content:
require_once('content/'.$_GET['page'].'.php');
当前htaccess配置:
Current htaccess configuration:
RewriteEngine On
# Add trailing Slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301]
# Make URLs sexy!
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
我可以使它与/ content文件夹中的顶级页面一起使用,但是,当我要包含的php文件位于/ content文件夹中的文件夹中时,它将无法工作。
I can get this to work with a top level page within the /content folder, however, when the php file I with to include is within a folder inside the /content folder, it does not work.
任何想法??我认为问题归结为在?page =变量中使用加号/。 htaccess似乎不喜欢这样。
Any ideas?? I believe the issue comes down to using an addition / in the ?page= variable. htaccess doesnt seem to like that.
经过一番游戏,我弄清楚了。我的正则表达式已关闭。
After some playing, I figured it out. My regex was off.
已更改:
# Make URLs sexy!
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
至:
RewriteRule ^(.*)(/)/?$ index.php?page=$1 [L]