Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Apache重定向保留URL_Regex_Apache_Mod Rewrite - Fatal编程技术网

Regex Apache重定向保留URL

Regex Apache重定向保留URL,regex,apache,mod-rewrite,Regex,Apache,Mod Rewrite,我正在制作一个运行在Apache2服务器上的JavaScript web应用程序。我想知道是否有可能(使用mod_rewrite或其他mod)使您键入的任何路径从根路径加载index.html,但保留URL 例如:“example.com/blah/blegh”将加载“example.com/index.html”,但地址栏仍将显示“example.com/blah/blegh”。如果您尝试键入“example.com/everything/is/index”,仍然会加载“example.com

我正在制作一个运行在Apache2服务器上的JavaScript web应用程序。我想知道是否有可能(使用mod_rewrite或其他mod)使您键入的任何路径从根路径加载index.html,但保留URL

例如:“example.com/blah/blegh”将加载“example.com/index.html”,但地址栏仍将显示“example.com/blah/blegh”。如果您尝试键入“example.com/everything/is/index”,仍然会加载“example.com/index.html”并在地址栏中显示“example.com/everything/is/index”,则情况相同

一个关于我需要使用的任何mod以及哪些命令可能是最好的简单答案就足够了。虽然代码示例非常有用,因为我对regex和Apache重写还不熟悉

感谢您抽出时间:)


注意:我这样做是因为我在导航(一个单页动态站点)时使用解析URL/标题到地址栏和选项卡标题中。我希望能够加载带有用户初始URL请求的root index.html,并像REST服务器一样响应用户的操作。

实际上,您希望在不重定向的情况下重写。这需要在Apache的httpd.conf中启用mod_代理和mod_重写

然后,重写应该如下所示:

Options +FollowSymLinks -MultiViews 
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [NC,L,QSA]
参考: