【问题标题】:.htaccess 301 redirect and remove .html combined.htaccess 301 重定向和删除 .html 组合
【发布时间】:2015-08-06 15:31:40
【问题描述】:

我正在尝试将所有 .html 文件从 stripelatice_ui 文件夹重定向到根目录并删除 .html 扩展名

localhost:8089/stripelatice_ui/home.html

localhost:8089/home

我尝试过使用

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [QSA,NC,L]


RewriteRule ^stripelatice_ui/(.*)$ /$1 [R=301,NC,L]

但是提示页面有重定向循环是错误的

【问题讨论】:

    标签: php html apache .htaccess redirect


    【解决方案1】:

    你可以使用:

    RewriteEngine On
    RewriteBase /stripelatice_ui/
    
    # To externally redirect /stripelatice_ui/file.html to /file
    RewriteCond %{THE_REQUEST} /stripelatice_ui/(.+?)\.html[\s?] [NC]
    RewriteRule ^ /%1 [R=301,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^.]+)/?$ $1.html [L]
    

    【讨论】:

    • 其实我想重定向 /stripelatice_ui/file.html 到 /file
    • 第一条规则有效,但 /file.html 和 /file 都没有服务。它给出了未找到的错误
    • 添加到我的答案中,不知道你的 .htaccess 在stripelatice_ui 目录中。
    猜你喜欢
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多