使用.htaccess从URL中删除目录

使用.htaccess从URL中删除目录,.htaccess,.htaccess,我正在尝试使用.htacess从生成的URL中删除目录(/category/) URL看起来像这样: 我想从URL中删除/category/ 我尝试了以下方法,但无效: RewriteRule category/(.*)$ /$1 [L,R=301] 完整访问权限如下所示: ## # @package Joomla # @copyright Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.

我正在尝试使用.htacess从生成的URL中删除目录(/category/)

URL看起来像这样:

我想从URL中删除/category/

我尝试了以下方法,但无效:

RewriteRule category/(.*)$ /$1 [L,R=301]
完整访问权限如下所示:

##
# @package    Joomla
# @copyright  Copyright (C) 2005 - 2016 Open Source Matters. All rights     reserved.
# @license    GNU General Public License version 2 or later; see LICENSE.txt
##

## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations     listed
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on     Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root home page
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#

RewriteEngine On
RewriteCond %{HTTPS} OFF
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteRule category/(.*)$ /$1 [L,R=301]

## End - Custom redirects

##
# Uncomment the following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

## BEGIN EXPIRES CACHING - OPTIMIZE THE SITE ##
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 2 days"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType application/x-shockwave-flash "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-javascript "access plus 1 month"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
## END EXPIRES CACHING - OPTIMIZE THE SITE ##
## BEGIN GZIP COMPRESSION - OPTIMIZE THE SITE ##
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
## END GZIP COMPRESSION - OPTIMIZE THE SITE ##
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf|svg)$">
    Header set Cache-Control "max-age=604800, public"
   Header unset ETag
   FileETag None
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "private"
  </filesMatch>
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers
##
#@Joomla
#@copyright版权所有(C)2005-2016开源事宜。版权所有。
#@license GNU通用公共许可证版本2或更高版本;请参阅LICENSE.txt
##
##没有目录列表
IndexIgnore*
##如果导致错误,可以注释掉,请参见上面的注释。
选项+FollowSymlinks
选项-索引
##Mod_正在使用中重写。
重新启动发动机
##开始-重写规则以阻止一些常见的漏洞攻击。
#如果您的网站出现问题,请对列出的操作进行注释
#在下面的行的开头添加一个#。
#这将试图阻止Joomla上最常见的“尝试”攻击!
#
#阻止任何试图在URL内对数据进行base64_编码的脚本。
RewriteCond%{QUERY\u STRING}base64\u encode[^(]*\([^)]*\)[或]
#阻止URL中包含标记的任何脚本。
重写cond%{QUERY_STRING}(|%3E)[NC,或]
#阻止任何试图通过URL设置PHP全局变量的脚本。
重写条件%{QUERY\u STRING}全局(|\[|\%[0-9A-Z]{0,2})[或]
#阻止任何试图通过URL修改_请求变量的脚本。
重写条件%{QUERY\u STRING}\u请求(|\[|\%[0-9A-Z]{0,2})
#返回403禁止标题并显示根主页的内容
重写规则。*index.php[F]
#
##结束-重写规则以阻止一些常见的漏洞攻击。
##开始-自定义重定向
#
#如果需要重定向某些页面,或将规范非www设置为
#www重定向(反之亦然),将代码放在这里
#重定向使用正确的重写规则语法和[R=301,L]标志。
#
重新启动发动机
重写条件%{HTTPS}关闭
重写规则(*)https://%{HTTP\u HOST}%{REQUEST\u URI}
重写规则类别/(.*)$/$1[L,R=301]
##结束-自定义重定向
##
#如果您的Web服务器的URL
#与物理文件路径没有直接关系。
#更新您的Joomla!目录(仅适用于根目录)。
##
重写基/
##开始-Joomla!核心SEF部分。
#
重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
#
#如果请求的路径和文件不是/index.php,则
#尚未在内部重写为index.php脚本
重写cond%{REQUEST_URI}!^/index\.php
#请求的路径和文件与物理文件不直接匹配
重写cond%{REQUEST_FILENAME}!-f
#请求的路径和文件与物理文件夹不直接匹配
重写cond%{REQUEST_FILENAME}!-d
#在内部将请求重写为index.php脚本
重写规则。*index.php[L]
#
##结束-Joomla!核心SEF部分。
##开始过期缓存-优化站点##
过期于
ExpiresDefault“访问加2天”
过期按类型图像/x图标“访问加1年”
过期按类型图像/jpeg“访问加1年”
过期按类型图像/png“访问加1年”
ExpiresByType image/gif“访问加1年”
过期按类型应用程序/x-shockwave-flash“访问加1年”
ExpiresByType文本/css“访问加1个月”
ExpiresByType文本/javascript“访问加1个月”
ExpiresByType应用程序/javascript“访问加1个月”
ExpiresByType应用程序/x-javascript“访问加1个月”
ExpiresByType text/html“访问加600秒”
ExpiresByType应用程序/xhtml+xml“访问加600秒”
##结束过期缓存-优化站点##
##开始GZIP压缩-优化站点##
mod_gzip_on Yes
是的
mod|gzip|item|u include file.(html?| txt | css | js | php | pl)$
mod_gzip_item_包含处理程序^cgi脚本$
mod_gzip_项目包括mime^text/*
mod_gzip_item_包括mime^application/x-javascript*
mod_gzip_项_排除mime^image/*
mod_gzip_item_排除rspheader^内容编码:.*gzip*
##结束GZIP压缩-优化站点##
#开始缓存控制头
标题集缓存控制“最大年龄=604800,公共”
标题未设置ETag
FileTag无
标题集缓存控制“最大年龄=604800,公共”
标头集缓存控制“专用”
标题集缓存控制“专用,必须重新验证”
#结束缓存控制头
站点根目录中的文件

此规则没有问题:

RewriteRule category/(.*)$ /$1 [L,R=301]

但是位置是错误的。你需要把它放在
重写引擎下的
行才能使它工作,否则Joomla的默认前端控制器规则将
请求URI
设置为
/index.php

正则表达式中的
^
表示“在URL的开头”。在你的例子中,“category”位不在开头URL的g-您是否尝试过删除
^
?谢谢,是的,刚刚尝试过,但仍然不起作用。您的.htaccess位于何处,其他现有规则是什么?