Apache重定向保持URL [英] Apache redirect keeping URL

查看:121
本文介绍了Apache重定向保持URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm making a JavaScript web app running on an Apache 2 server. I'm wondering if it's possible (either with mod_rewrite or some other mod) to make any path you type load the index.html from the root path, but keeping the 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".

For example: "example.com/blah/blegh" will load "example.com/index.html", but the address bar will still have "example.com/blah/blegh". Same if you tried typing "example.com/everything/is/index" would still load "example.com/index.html" and have "example.com/everything/is/index" in the address bar.

关于我需要使用的所有mod以及哪个命令可能是最佳的简单答案就足够了.尽管由于我是正则表达式和Apache重写的新手,所以代码示例将非常有用.

A simple answer about any mods I would need to use and which commands might be best would suffice. Though a code example would be very useful since I'm new to regex's and Apache rewriting.

谢谢您的时间:)

注意:之所以这样做,是因为我正在使用 History.js 进行解析导航时(一个一页动态网站),URL/标题进入地址栏和选项卡标题.我希望能够使用用户的初始URL请求加载root index.html并以类似于REST服务器的方式响应用户的操作.

Note: I'm doing this since I'm using History.js to parse URLs/titles into the address bar and tab titles while navigating (a one-page dynamic site). I'd like to be able to just load up the root index.html with the user's initial URL request and respond to users' actions that way much like a REST server.

推荐答案

实际上,您希望重写而不进行重定向.这需要在Apache的httpd.conf中启用mod_proxy和mod_rewrite.

Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.

然后,重写应如下所示:

Then, the rewrite should look like this:

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

参考:

  • What exactly does the Multiviews options in .htaccess?
  • htaccess rewrite without redirect
  • Apache: RewriteRule Flags

这篇关于Apache重定向保持URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆