简体   繁体   English

我怎样才能知道哪个页面为我服务?

[英]How can I tell which page serves me?

I am on a website. 我在一个网站上。 the URL reads something like https://somesite.com/serve 该URL的内容类似于https://somesite.com/serve

I need to tell the name of the page that is serving me. 我需要告诉我所服务页面的名称。

Like index.html , index.htm , etc... index.htmlindex.htm等...

从根本上来说,这是不可能的。

You want to know the file that is being served. 您想知道正在提供的文件。 Well probably you are facing url rewrite with htaccess or other techniques. 可能您正面临使用htaccess或其他技术进行的URL重写。 To tell which file it is probably is impossible if only you manage to get framework (if it is framework) in which the page is made. 如果仅要设法获取用于创建页面的框架(如果是框架),则要分辨出哪个文件可能是不可能的。 Then you can read in documentation which is the file to which the requests are aimed. 然后,您可以阅读文档,这些文档是请求所针对的文件。 Most frameworks will have one or several of these files. 大多数框架将具有一个或多个这些文件。 For example codeignighter will have only index.php, while symfony 2 will have app.php and app_dev.php (and others if you want different environments). 例如,codeignighter仅具有index.php,而symfony 2将具有app.php和app_dev.php(如果需要不同的环境,则还有其他)。 But normaly you cant know which file serves your request if url rewrite is made. 但是通常情况下,如果进行URL重写,您将无法知道哪个文件可以满足您的请求。


As mentioned @Dale you cant also beleave what urls say. 如@Dale所述,您也无法相信网址所说的内容。 Because you cant stick some extension at the end for it to look as file. 因为您不能在文件末尾加上一些扩展名才能使其看起来像文件。 Sometimes you can notice .php or more often .html / .htm at the end. 有时您会注意到.php或更常见的是.html / .htm结尾。

I'm not entirely sure what you mean. 我不确定您的意思。 But I'm certain you can find it with $_SERVER (Documentation can be found here ) 但是我敢肯定,您可以通过$ _SERVER找到它(文档可以在这里找到)

Good luck 祝好运

If you just trying to find out the page name then you can do this: 如果您只是想找出页面名称,则可以执行以下操作:

<?php
$currentFile = $_SERVER["PHP_SELF"];
$parts = explode('/', $currentFile);
echo $parts[count($parts) - 1];
?>

probably then you have a .htaccess with rewrite rules which looks something like: 可能然后您有了一个带有重写规则.htaccess文件 ,看起来像这样:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Else you probably would have query string instead which probably looked something like: 否则,您可能会有查询字符串,而不是类似以下内容的字符串:

index.php?c=products&m=view&id=345

(Assuming server supports .htaccess, mod_rewrite, mod_headers) (假设服务器支持.htaccess,mod_rewrite,mod_headers)

Temporarily use .htaccess RewriteRule to reveal all or matching filenames in a header. 临时使用.htaccess RewriteRule在标头中显示所有或匹配的文件名。

Example tags all php file headers with filename: 示例使用文件名标记所有php文件头:

<IfModule mod_rewrite.c>
RewriteEngine on
    <IfModule mod_headers.c>
        RewriteRule .*\.php$ - [E=FILENAME:$0]
        <FilesMatch ".php$">
           Header set MY-COOL-FILENAME "filename=%{FILENAME}e"
        </FilesMatch>
    </IfModule>
</IfModule>

Links 链接

Setting a filename inside the header with htaccess 使用htaccess在标头中设置文件名

View HTTP headers in Google Chrome? 在Google Chrome浏览器中查看HTTP标头?

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

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