【问题标题】:Can not rewrite slash rule in htaccess无法在 htaccess 中重写斜线规则
【发布时间】:2015-04-23 13:42:14
【问题描述】:

我需要在 htaccess 中添加代码以从 site.com/pagesite.com/page/ 打开我的页面以打开同一页面。这有很多代码,但它对我不起作用,因为我已经有一个代码可以删除 .html 结尾到目前为止我有这个。

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

如果用额外的斜线打开,我可以在这段代码中添加什么来重写?

这是完整的 htaccess 文件

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

    <IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 
    # Default directive
    ExpiresDefault "access plus 1 month"
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    # CSS
    ExpiresByType text/css "access plus 1 month"
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
    </IfModule>

    ErrorDocument 400 /400.html
    ErrorDocument 401 /401.html
    ErrorDocument 403 /403.html
    ErrorDocument 404 /404.html
    ErrorDocument 500 /500.html

    <IfModule deflate_module>
        # Enable compression for the following file types.
        AddOutputFilterByType            \
         DEFLATE                         \
          application/javascript         \
          text/css                       \
          text/html                      \
          text/javascript                \
          text/plain                     \
          text/xml
    </IfModule>

【问题讨论】:

    标签: .htaccess web url-rewriting slash


    【解决方案1】:

    使用这个.htaccess:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^.]+)/?$ $1.html [NC,L]
    

    【讨论】:

    • 嘿,它不起作用我把它放进去,当我打开 website.com/page/ 时仍然出现错误 404
    • 你说的。但仅此而已?
    • 你是什么意思?我用你写的替换了上面的代码
    • .htaccess 中没有其他内容?因为它必须工作如果page.html文件存在...
    • 我确实有更多,但我认为没有必要我编辑了我的帖子,请看。
    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    相关资源
    最近更新 更多