Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将所有地址栏请求重定向到一个索引页?并使用请求的子文件夹作为输入_Php_Javascript_Html_Ajax - Fatal编程技术网

Php 如何将所有地址栏请求重定向到一个索引页?并使用请求的子文件夹作为输入

Php 如何将所有地址栏请求重定向到一个索引页?并使用请求的子文件夹作为输入,php,javascript,html,ajax,Php,Javascript,Html,Ajax,我正在使用PHP、Ajax、JS和HTML,经过多次搜索后,我被谷歌搜索到了 如何让访问www.foo.com/bar的用户访问www.foo.com/index.php并使用bar作为输入 我希望避免为每个可能的值创建文件夹 我想将/bar保留在您想要查看的地址栏中。检查位置并通过javascript更改为您想要的任何内容: <script type="text/javascript"> // var x = ( cut out part of the current locati

我正在使用PHP、Ajax、JS和HTML,经过多次搜索后,我被谷歌搜索到了

如何让访问www.foo.com/bar的用户访问www.foo.com/index.php并使用bar作为输入

我希望避免为每个可能的值创建文件夹


我想将/bar保留在您想要查看的地址栏中。

检查位置并通过javascript更改为您想要的任何内容:

<script type="text/javascript">
// var x = ( cut out part of the current location )
// Then replace with whatever:
location.replace('http://www.example.com/');
</script>

//var x=(剪切当前位置的一部分)
//然后替换为:
位置。替换('http://www.example.com/');
示例:


另外,这里有一个替代mod_rewrite的php选项(这是您应该使用的,但如果您不能,还有其他方法):


使用Apache mod_在此处重写一个or,但uri如下:


http://example.com/index.php/controller/action/variables

假设您使用的是apache,您将需要使用mod rewrite。这是一个服务器端问题,对吗?您的服务器在获得www.foo.com/bar时必须提供一些页面。我猜您错过了一行:“我想避免为每个可能的值创建文件夹。”这是您的解决方案所需要的。@epasc我假设他不能使用mod_rewrite,因为他的问题表明仅使用php/js/html/ajax,因此,对于不能使用mod_rewrite的人来说,这些是最好的选择。