简体   繁体   中英

How can I tell which page serves me?

I am on a website. the URL reads something like https://somesite.com/serve

I need to tell the name of the page that is serving me.

Like index.html , index.htm , etc...

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

You want to know the file that is being served. Well probably you are facing url rewrite with htaccess or other techniques. 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). But normaly you cant know which file serves your request if url rewrite is made.


As mentioned @Dale you cant also beleave what urls say. 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.

I'm not entirely sure what you mean. But I'm certain you can find it with $_SERVER (Documentation can be found here )

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:

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)

Temporarily use .htaccess RewriteRule to reveal all or matching filenames in a header.

Example tags all php file headers with filename:

<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

View HTTP headers in Google Chrome?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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