PHP可以访问文件的.htaccess重写名称 [英] Can PHP access the .htaccess rewrite name of a file

查看:117
本文介绍了PHP可以访问文件的.htaccess重写名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.htaccess作品(不是专家,而是做了很多的复制和放大器;粘贴)。

My .htaccess works (not an expert, but do a lot of copy & paste).

我的一个网页一个典型的改写如下:

A typical rewrite for one of my pages looks like this:

RewriteRule ^my-grills-parts-and-service/?$ parts-service.php [NC,L]

...其中的URL HTTP://www.mydomain。 COM /我-烤架零件和服务/ 将调用部分-service.php文件。

...where the url "http://www.mydomain.com/my-grills-parts-and-service/" will invoke the parts-service.php file.

不过,我使用PHP来构建一个完全合格的URL,从什么是在地址栏。问题是,服务器变量$ _ SERVER ['SCRIPT_NAME']将返回部分-service.php,而不是什么实际上是在地址栏中,我-烤架零件和服务/\".

However, I am using php to construct a fully qualified URL, from what is in the address bar. The problem is, the server variable $_SERVER['SCRIPT_NAME'] will return "parts-service.php", rather than what is actually in the address bar, "my-grills-parts-and-service/".

我想PHP以某种方式阅读文字改写串,而不是实际的文件名。

I want php to somehow read the literal rewrite string, rather than the actual filename.

所以,我想PHP构建一个像这样的字符串:

So, I want php to construct a string like this:

$url = "http://www.mydomain.com/my-grills-parts-and-service/";

我希望我没有写一个数据表或开关如果块,因为这会可(曾在.htaccess,又在一个PHP文件)两次做的一切。

I hope I don't have to write a data table or switch or if block, because that would be doing everything twice (once in the .htaccess, and again in a php file).

推荐答案

您可以使用 $ _ SERVER ['REQUEST_URI'] 来获得真正的URL地址。

You can use $_SERVER['REQUEST_URI'] to get real url address.

使用此方法之前,检查@regilero评论。

Before using this method, check @regilero comment.

这篇关于PHP可以访问文件的.htaccess重写名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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