创建使用实际站点 URL 的漂亮 URL 时出现问题
我想创建类似于网站 downforeveryoneorjustme.com 的功能。他们使用漂亮的 URL 来获取任何给定站点的 URL。我确信他们使用 htaccess 来执行此操作,但是我使用的方法遇到了问题。
这是我的 .htaccess 文件,我用它来将站点 URL 发送到 file.php:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)?$ /file.php?var=$1
但是,当我输入类似的内容时 mysite.com/http://google.com
它发送到文件的变量是 http:/google.com
(缺少斜杠)。我不明白为什么会发生这种情况。
此外,当我输入诸如 mysite.com/existingfolder
之类的内容(其中 existingfolder
是我网站上的文件夹)时,它总是无法正常工作。它传递给文件的变量是 missing.html
而不是 existingfolder
。在这种情况下,文件不显示图像。找不到图像,我假设它是因为它在网站上不正确的文件夹中搜索图像。它可能认为它位于 existingfolder
中,而不是位于它应该位于的正常文件夹中。
有谁知道我为什么会遇到这些问题?我知道 htaccess,并且我假设它与此有关。
感谢您的任何帮助。
I want to create functionality similar to the site downforeveryoneorjustme.com. They use a pretty URL to take in the URL of any given site. I sure they use htaccess to do this, however the method i'm using is encountering problems.
This is my .htaccess file that I'm using to send the site URL to a file.php:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)?$ /file.php?var=$1
However when I type in something likemysite.com/http://google.com
the variable it sends the file is http:/google.com
(missing a slash). I can't figure out why this is occurring.
Also, when I type in something like mysite.com/existingfolder
, where existingfolder
is a folder on my site, it always works incorrectly. The variable it passes to the file is missing.html
instead of existingfolder
. In this case, the file doesn't display images. The image can't be found, and i'm assuming its because it's searching for the image in an incorrect folder on the site. That it might think it's in existingfolder
and not in the normal folder it should be in.
Does anyone know why I'm getting these problems? I'm knew to htaccess, and I'm assuming it has something to do with that.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
但我不是。我什至不确定他们是否使用 Apache。
mod_rewrite 并不总是解决所有 URL 处理问题。它肯定容易出现基于路径的 URL 处理的一些怪癖,包括删除双斜杠。
我建议从脚本中读取 Apache 特定的
REQUEST_URI
变量,而不是依靠重写来获取参数。这将为您提供浏览器请求的路径,无需任何处理。I'm not. I'm not even sure they're using Apache.
mod_rewrite is not always the answer to all URL-processing problems. It's certainly prone to some of the quirks of path-based URL handling, including the removal of double-slashes.
I suggest reading the Apache-specific
REQUEST_URI
variable from your script, rather than relying on rewrites to get a parameter. This will give you the path requested by the browser without any processing.