简体   繁体   English

php网站网址匹配问题

[英]php website url matching question

i am new to a php site, only familiar with .net web forms sites. 我是php站点的新手,仅熟悉.net Web表单站点。

i can't figure out how routing is working on this php site. 我不知道路由如何在这个php网站上工作。

www.oursite.com/suggestions.php is to suggestions.php www.oursite.com/suggestions.php是对Recommendations.php的访问
www.oursite.com/suggestions also loads the php fine www.oursite.com/suggestions还可以正常加载php
www.oursite.com/suggestions/ loads the php, but no css is applied www.oursite.com/suggestions/加载php,但未应用任何CSS
www.oursite.com/suggestions/anything - anything that comes after the '/' is ignored and suggestions is loaded without css. www.oursite.com/suggestions/任何内容-'/'之后出现的所有内容都将被忽略,并且建议将在没有CSS的情况下加载。 so oursite.com/suggestions////// works, as does oursite.com/suggestions/2/2/2/2/whatever 因此oursite.com/suggestions//////可以正常工作,就像oursite.com/suggestions/2/2/2/2/whatever

i have searched but not found any good explanation on how this is working. 我已经搜索过,但没有找到关于此工作原理的任何很好的解释。 can someone explain or provide a good resource? 有人可以解释或提供良好的资源吗?

thank you. 谢谢。

This is most certainly done using Mod_Rewrite, an Apache extension. 当然,这是使用Apache扩展Mod_Rewrite完成的。 You'll probably find a file called .htaccess in the public root, in which these rewriting rules are defined. 您可能会在公共根目录中找到一个名为.htaccess的文件,在其中定义了这些重写规则。

DouweM has the right answer as far as the friendly urls are concerned. 就友好的URL而言,DouweM具有正确的答案。

As for the CSS, it is probably because you are using relative URLs in your link tags: 至于CSS,可能是因为您在链接标记中使用了相对URL:

<link rel="stylesheet" href="site.css"/>

Change those to absolute URLs and it should solve that problem: 将这些更改为绝对URL,它应该可以解决该问题:

<link rel="stylesheet" href="/site.css"/>

The reason for this is that the browser makes the request for the CSS based on the directory it thinks it is in, even though your URL rewriting is changing that. 这样做的原因是,即使您的URL重写改变了浏览器,浏览器也会根据它认为所在的目录来请求CSS。 So, if the url is http://mysite.com/suggestions/ and you are using relative urls, the browser will request the css as http://mysite.com/suggestions/site.css which of course doesn't exist. 因此,如果该URL是http://mysite.com/suggestions/并且您使用的是相对URL,则浏览器将请求CSS作为http://mysite.com/suggestions/site.css ,这当然是不存在的。

www.oursite.com/suggestions.php is to suggestions.php
www.oursite.com/suggestions also loads the php fine

You probably have a .htaccess file that first checks whether or not a file of that name exists, and if it does serves it, then, if it doesn't, tries to route it to a php script. 您可能有一个.htaccess文件,该文件首先检查该名称的文件是否存在,如果确实存在该文件,则(如果不存在)尝试将其路由到php脚本。

www.oursite.com/suggestions/ loads the php, but no css is applied

The / means your browser considers ' /suggestions/ ' a directory. /表示您的浏览器将' /suggestions/ '视为目录。 If suggestions.php outputs HTML that contains a relative <link> to a stylesheet, eg <link href="style.css"> , your browser will request www.oursite.com/suggestions/style.css , rather than www.oursite.com/style.css as in the previous two cases. 如果suggestions.php输出的HTML包含与样式表相关的<link> ,例如<link href="style.css"> ,则您的浏览器将请求www.oursite.com/suggestions/style.css而不是www.oursite.com/style.css如前面的两种情况。

www.oursite.com/suggestions/anything

Same as the previous case, your browser will request the wrong css file, since it considers ' /suggestions/ ' a directory. 与前面的情况相同,您的浏览器将请求错误的css文件,因为它会将“ /suggestions/ ”视为目录。 (For a potential fix, take a look at Eric Petroelje 's answer.) (有关可能的解决方法,请查看Eric Petroelje的答案。)

As DouweM said, though, your best bet is to look directly at your .htaccess file and figure out what it does. 正如DouweM所说,最好的选择是直接查看.htaccess文件并弄清楚它的作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM