简体   繁体   English

将特定的虚拟网址重定向到index.html

[英]Redirect specific virtual urls to index.html

i currently try to rederict my language specific virtual url's to the index.html. 我目前尝试将特定于语言的虚拟网址重新访问到index.html。 sadly it won't work so i aks you here. 不幸的是,它无法正常工作,所以我在这里问您。

on my index.html page i set virtual urls with the history api such like this: 在我的index.html页面上,我使用历史API设置了虚拟网址,如下所示:

history.pushState(null, null, 'de');

so that works perfectly fine, but when i enter the url manually, the server tries to open the index.php/de, which dosent exists. 因此,它工作得很好,但是当我手动输入url时,服务器尝试打开index.php / de,其中存在该剂量。

my idea was to redirect all virtual urls for let's say "/de/" and "/en/" to the index.html file and keep the initial url. 我的想法是将所有虚拟网址(例如“ / de /”和“ / en /”)重定向到index.html文件,并保留初始网址。 i will then do the navigation and content loading stuff in the index.html with js. 然后,我将使用js在index.html中进行导航和内容加载。

  • domain.com/de -> opens the index.html and keeps the original url domain.com/de->打开index.html并保留原始网址
  • domain.com/en -> opens the index.html and keeps the original url domain.com/en->打开index.html并保留原始网址

my mod_rewrite code: 我的mod_rewrite代码:

RewriteEngine on
RewriteRule "^/de?$" "/index.html"

unfortunately this code redirect nothing. 不幸的是,这段代码没有重定向任何内容。 my server log say that the domain.com/de can not be found. 我的服务器日志显示找不到domain.com/de。

any ideas to fix this? 有什么解决办法吗?

cheers Marco 欢呼马可

RewriteRule removes the leading slash when you're in a htaccess. 在htaccess中, RewriteRule删除前导斜杠。
So you're trying to match a wrong path (that's why it does not work). 因此,您试图匹配错误的路径(这就是为什么它不起作用的原因)。

Also, get rid of " in the rule and add L flag after. 另外,在规则中删除" ,然后在其后添加L标志。

You can replace your code by this one 您可以用此代码替换您的代码

RewriteEngine On
RewriteRule ^(?:de|en)$ /index.html [L]

Note: make sure mod_rewrite is enabled (and htaccess files allowed) in your Apache config 注意:确保在Apache配置中启用了 mod_rewrite (并允许htaccess文件)


EDIT: taking your comment below into consideration 编辑:将您的评论纳入考虑范围

RewriteEngine On
RewriteRule ^(?:de|en)(?:$|/.+) /index.html [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM