繁体   English   中英

为什么.htaccess RewriteRule不起作用

[英]Why is .htaccess RewriteRule not working

我有两个重写规则,第一个有效,第二个无效。 有人可以解释为什么吗?

我希望任何带有文本“ online-marketplace-development”的URL重定向到URL http://jeyjoo.com/blog/online-marketplace-development-what-we-learnt

mod_rewrite已打开,所有其他规则均有效。 我的.htaccess文件如下:

RewriteEngine On
##following rule works
RewriteRule ^blog/blog(.*)$ http://jeyjoo.com/blog$1 [L,R=301]
##the following rule doesn't seem to do anything
RewriteRule ^online-marketplace-development(.*)$ http://jeyjoo.com/blog/online-marketplace-development-what-we-learnt

根据要求,完整的.htaccess如下:

<IfModule mod_deflate.c>
    #The following line is enough for .js and .css
    AddOutputFilter DEFLATE js css

    #The following line also enables compression by file content type, for the following list of Content-Type:s
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml

    #The following lines are to avoid bugs with some browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
    </FilesMatch>
    # 1 YEAR
    <FilesMatch "\.(ico|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=29030400, public"
    </FilesMatch>
    # 1 WEEK is 604800
    <FilesMatch ".(xml|txt|css|js)$">
    Header set Cache-Control "max-age=904800, proxy-revalidate"
    </FilesMatch>
    # 1 MIN
    #<FilesMatch ".(html|htm|php)$">
    #Header set Cache-Control "max-age=60, private, proxy-revalidate"
    #</FilesMatch>
</IfModule>
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that disallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
##

## 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 block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out 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 homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects

RewriteRule ^blog/blog(.*)$ http://jeyjoo.com/blog$1 [L,R=301]
RewriteRule ^online-marketplace-development(.*)$ http://jeyjoo.com/blog/online-marketplace-development-what-we-learnt 
RewriteCond %{HTTP_HOST} ^www\.jeyjoo\.com [NC]
RewriteRule ^(.*)$ http://jeyjoo.com/$1 [R=301,NC,L]

## End - Custom redirects

##
# Uncomment 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.

谢谢

[L]标志使mod_rewrite停止处理规则集。 在大多数情况下,这意味着如果规则匹配,将不再处理其他规则。 请参阅L标志上的Apache文档

规则1已经适用于您的第二条规则,因此请从这个角度重新考虑第二条规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM