【问题标题】:delete /folder in url path with htaccess使用 htaccess 删除 url 路径中的 /folder
【发布时间】:2017-04-22 10:02:54
【问题描述】:

我创建了一个网站,其中包含除“页面”文件夹中的索引之外的所有页面 我想制定一个改变的重写规则:

www.mydomainname.com/pages/about.php

www.mydomainename.com/about.php

我的实际 .htacces 删除了我的页面的 .php,但我找不到在我的 url 路径中删除“pages”文件夹的解决方案:

Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    以下规则应该有效,但您必须确保它与您的其他规则不冲突,

    RewriteRule ^([\w-]+)$ pages/$1 [L]
    

    【讨论】:

    • 所以实际上我需要制作一个新的 RewriteCond ?
    • 在您的根 .htaccess 中使用此规则,或者在所有规则中无条件使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多