【问题标题】:.htaccess - Remove a word from url.htaccess - 从 url 中删除一个单词
【发布时间】:2017-04-06 02:50:37
【问题描述】:

我有一个项目目录结构如下

| project
 --| controllers
 --| views
   --| index.php
   --| .htaccess
 --| config
 --| .htaccess

这是我的主要 .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(.*)?$ views [L]
</IfModule>

和我的观点 .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^.+$ index.php [L]
</IfModule>

我可以将我的所有请求重定向到 views/index.php。当我转到 www.example.com/project 时,它将被重定向到 www.example.com/project/views

我的主要问题是我不想在我的 URL 中有视图。如果我去 www.example.com/project 它应该执行 views/index.php 但 URL 不会改变。谁能帮我解决这个问题?

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite clean-urls


    【解决方案1】:

    将其保存在 main .htaccess 中:

    RewriteEngine On
    RewriteRule .* views/$0 [L]
    

    然后在.views/.htaccess中这样写:

    RewriteEngine on
    
    RewriteRule ^index\.php$ - [L,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-12
      • 2012-06-06
      • 2020-12-30
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      相关资源
      最近更新 更多