如何仅将.php文件发送到同一页面? [英] How can I send only .php files to same page?

查看:68
本文介绍了如何仅将.php文件发送到同一页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要这样的url

mysite.com/language/page/somethingelse

并始终在同一文件中进行处理,该文件为 index.php

And processing that always in the same file which is index.php.

但仅用于 .php 文件。我不想重定向 .js .css .xml ,图像文件等。

But only for .php files. I don't want to redirect .js or .css or .xml, image files and so on.

此外,该项目将位于子文件夹中,这意味着它将位于另一个文件夹中而没有任何关系。因此,可以像这样访问它:

Plus, this project will be in a subfolder, meaning it will be inside another with no relation whatsoever. Therefore, it will be accessible like this:

mysite.com/extras/mydifferentproject/language/page/something else

所以我认为<$ c中的 .htaccess 文件$ c> mydifferentproject 文件夹是否需要此行?

So I suppose the .htaccess file inside mydifferentproject folder will need this line?

RewriteBase extras/mydifferentproject/


推荐答案

您可以将其作为 .htacces

RewriteEngine On
RewriteRule ^(?!index\.php$). index.php [NS,L,DPI]






在文件夹



之后捕获值。从 .htacces 都位于 URL的将被捕获。为了获取路径并获取它是否在文件夹中并进行进一步处理,此功能将有所帮助。


Catching the value after the folder

From the folder that the .htacces is in all the URL's will be caught. In order to get the path and get if it's in a folder and process it further this function will help.

function getPath($path){
    $called = __FILE__;
    $called_dir = str_replace("\\","/",pathinfo($called)["dirname"]);
    $root = str_replace($_SERVER["DOCUMENT_ROOT"], "",$called_dir);
    $from = '/'.preg_quote($root, '/').'/';
    return preg_replace($from,"",$path,1);
}






使用方法




How to use

getPath($_SERVER["REQUEST_URI"]);

这将为您提供所在文件夹后面的字符串,因此将其排除在外

This will get you the string that is behind the folder it is in, so it excludes the folder it is in.

.htacces :位于文件夹 /文件夹

url example.com/文件夹/ some / values
中的 getPath()函数的
结果 index.php / some / values ,因为它在文件夹中文件夹

.htacces: is in the folder /folder
url: example.com/folder/some/values
result of the getPath() function in index.php : /some/values as it's in the folder folder.

如果您的网址是 example.com/index.html 是,但是 .htacces 文件夹中行为正常。 (将加载index.html)

In the case that your URL example.com/index.html is, but the .htacces is in folder the behavior is just normal. (will load index.html)

通过处理路径或任何使用路径的过程加载文件时。在 html 中加载请求文件时,请确保定义文件的加载位置 base ,否则将从上方输入路径输入,并将其视为文件夹,而不是值或不应查看的内容。

When loading files through a process of handeling the path, or anything you do with it. When loading requesting files in the html be sure to define the base of where he files should be loaded from, otherwise it will take the path input from above and see those as folders, and not as values or something it should not look at.

示例

<base href="/folder/">

这篇关于如何仅将.php文件发送到同一页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆