【问题标题】:htaccess redirect to a maintenance page and remove filename with extansion from URLhtaccess 重定向到维护页面并从 URL 中删除带有扩展名的文件名
【发布时间】:2016-08-31 05:32:08
【问题描述】:

我的 htaccess 中有此代码,它重定向到维护页面,但如果不显示文件夹名称和文件名 (/mce/mce.php) 并且只显示域 url,我就无法让它重定向domain.com/website:

RewriteEngine On
RewriteBase /website/

RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4
RewriteCond %{REQUEST_URI} !/website/mce/mce.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /website/mce/mce.php [R=302,L]

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    你可以使用这条规则:

    RewriteEngine On
    RewriteBase /website/
    
    RewriteRule \.(jpe?g?|png|gif|ics|css|js)$ - [L,NC]
    
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REMOTE_ADDR} !=1.2.3.4
    RewriteRule . /website/ [L,R=302]
    
    RewriteCond %{REMOTE_ADDR} !=1.2.3.4
    RewriteRule ^ mce/mce.php [L]
    

    【讨论】:

    • 感谢您的回复。它几乎就在那里,但我更喜欢domain.com/website 之后的所有内容,比如domain.com/website/fr/file 将只显示域domain.com/website,如果我只输入domain.com/website,我也会丢失背景.png,但如果我在它之后添加一些东西,那么背景没问题。
    • 我收到错误:The page isn’t redirecting properly
    • 它根本不重定向,它显示我的网站但没有 css
    • 首先我从domain.com/website 开始,但如果我输入domain.com/website/dd/ee,它会剪切website 之后的所有内容,并显示我的网站首页没有css
    • 如果没有您的帮助,我不会这样做!谢谢。
    猜你喜欢
    • 2017-04-30
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    相关资源
    最近更新 更多