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


How can I redirect all address bar requests to one index page? And use a requested subfolder as input

我正在使用PHP, Ajax, JS和HTML,经过多次搜索,我是每个谷歌plex。

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

我想避免为每个可能的值创建一个文件夹。

我想在地址栏中保留/bar

使用Apache mod_rewrite这里的一个例子或使用php,但像这样的uri:

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

您需要查看mod_rewrite

检查位置并通过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>

例子:

http://www.tizag.com/javascriptT/javascriptredirect.php

http://andylangton.co.uk/articles/javascript/javascript-redirect-scripts/

http://www.javascriptredirect.com/timed.htm


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

php mod_rewrite