2017-02-02 11 views
2

.htacessを使用して、生成されたURLからディレクトリ(/ category /)を削除しようとしています。.htaccessを使ってURLからディレクトリを削除する

https://domain.com/folder1/folder2/category/folder3/product

私はURLから/ /カテゴリを削除する:

URLは次のようになります。

私は次のことを試してみたが、それは働いていない:

RewriteRule category/(.*)$ /$1 [L,R=301] 
次のように

全htaccessファイルは、次のとおりです。

## 
# @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 

サイト

+0

正規表現の '^'は 'URLの先頭にある'という意味です。あなたのケースでは、 'category'ビットはURLの先頭にありません。あなたは '^'を削除しようとしましたか? –

+0

ありがとうございます。はい、それを試しましたが、まだ動作していません。 – RustyIngles

+0

.htaccessはどこにありますか、他の既存のルールは何ですか? – anubhava

答えて

0

のルートこのルールでは、ファイル罰金:

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

しかし、位置が間違っています。そうでないと動作させるには、RewriteEngine On行の直下に置く必要があります。JoomlaのデフォルトのフロントコントローラルールではREQUEST_URI/index.phpとなっています。

関連する問題