问题描述
我被困在一个情况与htaccess的 - 没有在堆栈中的previous的解决方案似乎帮助我,让我写一个新的。这里的问题是:
I'm stuck in a situation with htaccess - None of the previous solutions in stack seems to help me so I'm writing a new one. Here is the problem:
我希望所有的请求,在默认情况下,如果犯规存在请求的资源加以研究 http://www.example.com/folder/public_html/
文件夹中,应该将请求路由到 http://www.example.com/index.php
I want all the requests to be looked into http://www.example.com/folder/public_html/
by default and if the requested resource doesnt exist in that folder, the request should be routed to http://www.example.com/index.php
例:我把对 http://www.example.com/example.php
的要求,所以默认情况下,服务器应该看看 /文件夹/的public_html /使用example.php
,如果该文件不存在,那么它应该通过索引文件中的站点即 /index.php?request=example的根源进行路由。 PHP
Example:I place a request for http://www.example.com/example.php
, so by default, the server should look into /folder/public_html/example.php
and if the file is not there then it should be routed via the index file in the root of the site i.e. /index.php?request=example.php
请帮忙,我非常卡住
推荐答案
与目录中的这条规则创建的.htaccess http://www.example.com/
Create a .htaccess with this rule in the directory http://www.example.com/
RewriteEngine on
RewriteRule ^(.*)$ /folder/public_html/$1 [L]
和本中的.htaccess中 http://www.example.com/folder/public_html/
And a .htaccess with this in http://www.example.com/folder/public_html/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?request=$1 [R]
(如果你只是想显示/index.php?request=example.php,但不希望浏览器重定向,用[L]而不是[R])
(If you only want to show /index.php?request=example.php but do not want the browser to redirect, use [L] instead of [R])
编辑:
如果你想的重定向应用于/folder/public_html/file.php如果的文件存在的,在第二次的.htaccess中加入这一行:
If you want to redirect to /folder/public_html/file.php if the file exists, add these lines in the second .htaccess:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [R]
默认的文件/folder/public_html/file.php显示,如果它的存在,因为在第一个.htaccess中的重写规则,但浏览器的不重定向。
By default the file /folder/public_html/file.php is shown if it exists because of the rewrite rule in the first .htaccess, but the browser doesn't redirect.
这篇关于htaccess的重写默认目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!