【问题标题】:Redirect page without page extention in javascript在javascript中重定向没有页面扩展名的页面
【发布时间】:2018-02-04 17:03:42
【问题描述】:

我有一个页面,比如说

http://www.mypage.com/pageone.html

我正在使用 javascript 重定向它,如下所示

window.location.replace("http://www.facebook.com/pageone");

但是要重定向页面它需要输入“.html”我如何在http://www.mypage.com/pageone.html之后省略“.html”扩展名

简而言之,我的预期链接是:http://www.mypage.com/pageone

【问题讨论】:

  • 你可以用 .htaccess 试试看。
  • 如果你不使用路由,只提供.html文件,你也可以创建一个名为pageone的目录,并在目录中放置一个index.html
  • 谢谢 Nicholas,你的伎俩成功了。

标签: javascript redirect


【解决方案1】:

试着理解这个对我有用的小例子:

RewriteEngine on
RewriteBase /
RewriteCond %{http://www.techdefeat.com/index.html} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.techdefeat.com/$1 [R=301,L]

上面的例子将把这个:http://www.techdefeat.com/index.html替换成这个:http://www.techdefeat.com/index

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    相关资源
    最近更新 更多