【发布时间】:2015-05-17 16:21:42
【问题描述】:
在我的单页 web 应用程序中,我使用了 html5 历史 API,以便 url 可以具有 REST 模式 (/section1/stuff1..),我计划制作一种 javascript 路由器来导航到多个部分页面取决于 url 路径。
现在我仍在本地服务器(wamp)上工作,我添加了一个 .htaccess 文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php/$1 [L]
到包含对页面某些部分(例如子域/sectionN)的引用的 url 路径的应用程序根目录可以始终重定向到 index.php 并且重定向成功 但是所有外部资源都失败了加载,我得到了:
Resource interpreted as Image but transferred with MIME type text/html: "http://localhost/subdomain/section1/images/imgname.gif".
这是合乎逻辑的,因为 images 文件夹位于应用程序根目录中,而不是在 /section1 文件夹下,并且 .htaccess 规则 RewriteRule (.*) index.php/$1 [L] 应该只使用 /images/imgname.gif 部分并将其连接在 http://localhost/subdomain/ 之后。
我发现this 是一个类似的问题,所以我像这样重写 .htaccess 文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?section1/(.+)$ index.php/$1
RewriteRule (.*) index.php/$1 [L]
但我有一个500 Internal Server Error。
【问题讨论】:
标签: php regex .htaccess mod-rewrite wampserver