【发布时间】:2015-04-25 14:53:10
【问题描述】:
我试图美化我网站上动态生成页面的 URL,这样当用户访问虚拟 URL topicview/interesting-user-friendly-text 时,他会真正看到 topicview.php?topicid=123
我在 .htaccess 文件中添加了必要的代码,以将 URL 的 topicview/interesting-text 部分替换为 topicview.php?topicname=interesting-test,但正则表达式一直出错。
所以,我更改了正则表达式以返回整个 URL,这样我就可以看到为什么它不能使用此代码:
#Allow for topicview/topic-name URLs
RewriteRule (.+)$ topicview.php?topicname=$1 [L]
然后我访问了topicview/user-friendly-text。我不确定这是否是网络解决方案托管所独有的,但是,当我检查 topicname GET 参数时,我得到了这个字符串作为回报:
data/1/2/323/232/823238/user/999999/htdocs/topicview.php
这个网址没有显示在topicnameGET参数中,只是一个普通的文件,比如index.php或者topicview.php,如果我只是访问网址index.php或者topicview.php的话
为什么 URL 在 Apache 服务器内部是这样表示的,我如何重写我的 mod_rewrite 代码来为 topicview.php?topicid=1 页面获取更用户友好的虚拟 URL?
谢谢
【问题讨论】:
-
当您使用字符串参数访问 topicview 并放置 var_dump($_GET); 时显示什么
-
like "topicview.php?topicid=4" - 这就是字符串参数的意思吗?
-
您能否使用此代码
<?php phpinfo(); ?>创建一个名为info.php的文件,然后打开http://domain.com/info.php以检查它的DOCUMENT_ROOT值是多少。 -
是的,
data/1/2/323/232/823238/user/999999/htdocs是 phpinfo() 报告的 Document_Root 值。有没有办法让 RewriteRule 的 Pattern 部分只查看 Request_URI,这是一个更简单的topicview.php?
标签: php apache .htaccess mod-rewrite hosting