【问题标题】:htaccess rewrite url and navigate to specified pagehtaccess 重写 url 并导航到特定页面
【发布时间】:2018-04-22 01:44:03
【问题描述】:

我已使用 htaccess 从我网站的所有页面中禁用 .php 扩展名。现在我的网站可以导航为

  1. www.domainname.com/page1
  2. www.domainname.com/page2
  3. www.domainname.com/page3...

现在在网站的所有页面中,对于某些页面,我需要在 URL 中添加前缀,例如

  1. www.domainname.com/mypages/page5
  2. www.domainname.com/mypages/page6

如何在不创建名为“mypages”的子目录的情况下使用 htaccess 做到这一点?

【问题讨论】:

  • 您能否通过编辑问题来显示您现有的 .htaccess。
  • 重写规则 ^([^\.]+)$ $1.php [NC,L]

标签: php apache .htaccess mod-rewrite


【解决方案1】:

您可以在站点根目录 .htaccess 中使用它:

RewriteEngine On

## some pages need to have mypages/
RewriteRule ^mypages/([\w-]+)/?$ $1.php [L,NC]

## for rest internally rewrite /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

【讨论】:

    猜你喜欢
    • 2018-06-15
    • 2017-07-18
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多