【问题标题】:Mask a directory folder name with htaccess使用 htaccess 屏蔽目录文件夹名称
【发布时间】:2016-03-04 23:20:47
【问题描述】:

我有这个 URL:https://example.com/sub/product,我不想在我的 URL 中显示“子”,因此最终 URL 看起来像 https://example.com/product,并将索引 URL 重定向到这个 URL。是否可以?这是我当前的 .htaccess 文件:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ReWriteRule ^([a-z\-0-9]+)$ index.php?goto=$1 [L,NC]
ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)$  index.php?goto=$1&catidx=$2     [L,NC]
ErrorDocument 404 /404/404.php

【问题讨论】:

    标签: .htaccess url-rewriting


    【解决方案1】:

    您可以使用以下内容:

     RewriteEngine on
    
    #--redirect from "/sub/foo to "/foo"--#
    RewriteCond %{THE_REQUEST} /sub/([^\s]+) [NC]
    RewriteRule ^ /%1 [L,R]
    #--rewrite "/foo" to its orignal location "/sub/foo"
    RewriteRule %{REQUEST_FILENAME} !-d
    RewriteRule %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ /sub/$1 [L,QSA]
    

    【讨论】:

    • 感谢您的回答,但它对我不起作用。当我添加此代码时,我的 css 文件在某些​​页面中被破坏,并且在某些页面中给出 500 ..我认为我不能正确使用旧代码。 .任何想法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    相关资源
    最近更新 更多