网络解决方案托管的URL看起来怪怪的Apache服务器 [英] Network Solutions hosting URL looks weird for Apache server
问题描述
我试图prettify网址在我的网站动态生成的页面,这样当用户访问虚拟网址 topicview /有趣的,人性化的文本
他真的会被看到,引擎盖下, topicview.php?topicid = 123
I was trying to prettify URLs for dynamically generated pages on my website, so that when a user visited the virtual URL topicview/interesting-user-friendly-text
he would really be seeing, under the hood, topicview.php?topicid=123
我添加了必要的code到我的.htaccess文件来替换 URL的topicview /有趣的文本
部分以 topicview。 PHP?topicname =有趣的测试
,但正则表达式保持哑火。
I added the necessary code to my .htaccess file to replace the topicview/interesting-text
part of the URL with topicview.php?topicname=interesting-test
, but the Regex kept misfiring.
于是,我改变了正则表达式返回整个URL,这样我能看到为什么它不工作与此code:
So, I changed the Regex to return the entire URL so I could see why it wasn't working with this code:
#Allow for topicview/topic-name URLs
RewriteRule (.+)$ topicview.php?topicname=$1 [L]
我随后走访 topicview /人性化的文本
。我不知道这是否是唯一的网络解决方案托管服务,但是,当我检查了 topicname
GET放慢参数,我得到的回报此字符串:
I then visited topicview/user-friendly-text
. I'm not sure if this is unique to Network Solutions hosting, however, when I examined the topicname
GET paramter, I got this string in return:
数据/ 1 /三百二十三分之二/823238分之232/用户/ 999999 / htdocs中/ topicview.php
该URL中未显示的 topicname
GET参数,只是一个普通的文件,如的index.php
或 topicview.php
,如果我只是访问网址的index.php
或 topicview.php
This URL was not displayed in the topicname
GET parameter, just a regular file, like index.php
or topicview.php
, if I just visit the URL index.php
or topicview.php
为什么URL内部重新psented这样对Apache服务器$ P $,我怎么可以重写我的的mod_rewrite
code,以获得更人性化虚拟网址为 topicview.php?topicid = 1
网页?
Why is the URL internally represented like this to the Apache server, and how can I rewrite my mod_rewrite
code to get a more user friendly virtual URL for the topicview.php?topicid=1
pages?
感谢
推荐答案
匹配的重写规则的模式通常是类似REQUEST_URI,但您所描述的行为表明,它是匹配对REQUEST_FILENAME或类似的东西它是文件路径包括完整的文档根目录。
The pattern matched in a RewriteRule is normally the similar to the REQUEST_URI but the behaviour you describe suggests it is matching against the REQUEST_FILENAME or something similar which is the file path including the full document root.
这会建议你重写规则是不是在你的.htaccess文件,而是在你还是在Apache的配置文件的规则,是否正确?
This would suggest your RewriteRule is not in your .htaccess file but instead in your or rules in the Apache config files, correct?
相反,你应该设法得到你想要使用的RewriteCond这样可以保证你匹配对REQUEST_URI的值,例如:
Instead you should try getting the value you want using a RewriteCond so you can guarantee you are matching against the REQUEST_URI, for example:
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule . topicview.php?topicname=%1 [L]
请注意在%1,而不是$ 1,它允许您使用的的RewriteCond捕获的值。
Note the %1 rather than $1 which allows you to use values captured in the RewriteCond.
这篇关于网络解决方案托管的URL看起来怪怪的Apache服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!