2012-08-15 69 views
-4

可能重复:
How to redirect all requests to index.php and keep the other GET params?
Rerouting all php requests through index.php如何为一组路径调用特定的PHP脚本?

假设我们有/var/www/someapp/index.php脚本。现在,我们怎样才能使Apache服务器发送所有喜欢

http://somedomain.info/someapp/alpha 
http://somedomain.info/someapp/beta 
http://somedomain.info/someapp/beta/gamma 
http://somedomain.info/someapp/epsilon/omega 

...到非常index.php脚本网址的请求的,以及我们如何能够从PHP脚本中检索完整的路径?

+0

请参阅[StackOverflow常见问题](http://stackoverflow.com/faq),特别是关于[不要问什么](http://stackoverflow.com/faq/#dontask)的部分,即:* “如果你可以想象一整本书可以回答你的问题,那么你的问题就太多了。”* – orourkek 2012-08-15 22:27:43

+3

此外,这是[this]的重复(http://stackoverflow.com/questions/9694118/rerouting-all- php-requests-through-index-php),[this](http://stackoverflow.com/questions/3776714/htaccess-rewriting-all-requests-to-a-single-controller?rq=1),[this ](http://stackoverflow.com/questions/5214502/how-to-redirect-all-requests-to-index-php-and-keep-the-other-get-params)和[this](http: //stackoverflow.com/questions/2669258/redirect-everything-to-index-php),名称*只有几个* ... – orourkek 2012-08-15 22:30:50

+2

[这里有几十个更多](https://www.google.com/search q =站点%3Astackoverflow.com +重定向+〜+所有子目录〜+至+〜+单文件),如果任何人有兴趣。 – orourkek 2012-08-15 22:40:27

回答

1

通常这是通过重写规则(即Apache上的mod_rewrite)完成的。这样的Apache可能涉及修改conf文件为主机,或施加在Web根.htaccess文件下面(假设主机配置允许这样的覆盖)

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^someapp/(.*)$ /someapp/index.php?q=$1 [L] 

这将请求重定向到index.php文件(不更改浏览器地址栏中的URL),并通过GET将'someapp /'作为参数'q'传递给脚本,只要URI不匹配一个实际的文件或目录。

+3

4k代表,你不能识别一个愚蠢? (这实际上是一个愚蠢的愚蠢行为......) – orourkek 2012-08-15 22:32:56

+0

@orourkek当然重定向主题存在于多个地方。然而,这个特定的一个并不处理将所有请求重定向到index.php,而是处理特定子目录中的请求。这真的是我回答它的原因。 – 2012-08-15 22:35:50

+2

真的吗?而不是链接到许多回答这种特殊性的问题,[这里有一大堆的列表](http://bit.ly/SoDrP1)。 *仍然是一个重要的诱惑*,如果OP甚至试图寻找答案,很容易找到答案。 – orourkek 2012-08-15 22:39:04

相关问题