Apache 创建重写规则,如果包含uri segmet重定向到php,则转到html文件

Apache 创建重写规则,如果包含uri segmet重定向到php,则转到html文件,apache,.htaccess,mod-rewrite,laravel-4,Apache,.htaccess,Mod Rewrite,Laravel 4,现在我使用artisan作为我的Web服务器,因为我在本地和server.php上工作,可以模拟mod_rewrite: // This file allows us to emulate Apache's "mod_rewrite" functionality from the // built-in PHP web server. This provides a convenient way to test a Laravel // application without having in

现在我使用artisan作为我的Web服务器,因为我在本地和server.php上工作,可以模拟mod_rewrite:

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' and file_exists($requested))
{
    return false;
}
if(substr( $uri, 0, 5 ) === '/api/')
    require_once $paths['public'].'/index.php';
else
    require_once $paths['public'].'/index.html';
所以我要做的是,如果我的路线是这样的:

www.mydomain.com/api/something

index.php
将负责该请求

对于其他内容,它将是
index.html

这两个文件都在公用文件夹中

很快我就要把它部署到我的Web服务器上,我怎么能用
.htacces
完成同样的事情呢

这就是我所拥有的,但我认为这行不通

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    <Location /api>
        FallbackResource /index.php
    </Location>
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^ index.html [L]

</IfModule>

选项-多视图
重新启动发动机
#重定向尾部斜杠。。。
重写规则^(.*)/$/$1[L,R=301]
FallbackResource/index.php
重写规则^(.*)/$/$1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.html[L]
您可以尝试以下代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]

# handle /api/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (^|/)api(/|$) index.php [L,NC]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
如果我是你,我会安装一个真正的web服务器(并将其配置得尽可能接近生产服务器)——这样,你最终会有最少的惊喜。你可能已经知道重写你想要的方式是否有效。评论中承诺的“便捷方式”最终只会带来更多的工作。