【问题标题】:How to remove a word from the URL with .htaccess?如何使用 .htaccess 从 URL 中删除一个单词?
【发布时间】:2017-03-12 17:38:39
【问题描述】:

我想将blog.byperte.com/blog/article 重定向到blog.byperte.com/article。该博客基于 Anchor CMS 构建,具有以下 .htaccess 文件:

Options -indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>

【问题讨论】:

  • 您是否有通过 URL (blog.byperte.com/blog/article) 发送的参数,例如文章 ID 或标题?
  • 我想是的。 PHP 不是我的强项。

标签: php .htaccess web anchor-cms


【解决方案1】:

要从 URL 中删除文件目录,请在 .htaccess 中使用它:

RewriteEngine On
RewriteRule ^blog/(.*)$ /$1 [L,R=301]

确保在测试之前清除缓存。

【讨论】:

  • 我明天试试,看看效果如何。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2017-04-06
  • 2020-12-30
  • 1970-01-01
  • 2012-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多