Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 为什么.htaccess重写规则不起作用_Apache_.htaccess_Mod Rewrite_Url Rewriting_Rewrite - Fatal编程技术网

Apache 为什么.htaccess重写规则不起作用

Apache 为什么.htaccess重写规则不起作用,apache,.htaccess,mod-rewrite,url-rewriting,rewrite,Apache,.htaccess,Mod Rewrite,Url Rewriting,Rewrite,我有两条重写规则,第一条有效,第二条无效。有人能解释一下原因吗 我想任何与文本“在线市场发展”的网址重定向到该网址 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

我有两条重写规则,第一条有效,第二条无效。有人能解释一下原因吗

我想任何与文本“在线市场发展”的网址重定向到该网址

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.

#下面的行对于.js和.css已经足够了
AddOutputFilter DEFLATE js css
#下一行还支持按文件内容类型对以下内容类型列表进行压缩:s
AddOutputFilterByType DEFLATE text/html text/plain text/xml应用程序/xml
#以下几行是为了避免某些浏览器出现bug
浏览器匹配^Mozilla/4 gzip纯文本/html
浏览器匹配^Mozilla/4\.0[678]无gzip
BrowserMatch\bMSIE!没有gzip!仅限gzip文本/html
头附加变量:接受编码
#一年
标题集缓存控制“最大年龄=29030400,公共”
#一周是604800
标题集缓存控制“最大年龄=904800,代理重新验证”
#1分钟
#
#标头集缓存控制“最大年龄=60,专用,代理重新验证”
#
##
#如果您选择使用此文件,请完整阅读此文件!
#
#此部分下方的行:“选项+FollowSymLinks”可能会导致问题
#使用一些服务器配置。使用mod_rewrite时需要它,但可能已经存在
#由服务器管理员以不允许在中更改的方式进行设置
#您的.htaccess文件。如果使用它导致服务器出错,请将其注释掉(添加到
#行的开头),在浏览器中重新加载站点并测试sef url。如果有效的话,
#它已由服务器管理员设置,您不需要在此处设置。
##
##没有目录列表
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]
#
##结束-重写规则以阻止一些常见的漏洞攻击。
##开始-自定义重定向
重写规则^blog/blog(.*)$http://jeyjoo.com/blog$1[L,R=301]
重写规则^online marketplace development(.*)$http://jeyjoo.com/blog/online-marketplace-development-what-we-learnt 
重写cond%{HTTP_HOST}^www\.jeyjoo\.com[NC]
重写规则^(.*)$http://jeyjoo.com/$1[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部分。

谢谢,

标记[L]会导致mod_rewrite停止处理规则集。在大多数上下文中,这意味着如果规则匹配,将不会处理更多的规则


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

为什么不:
RewriteRule^博客/在线市场开发。*$http://jeyjoo.com/blog/online-marketplace-development-what-we-learnt
@anubhava我刚试过这个,但还是没有改变。不,只有顶级文件let-us.Ji@anub哈,我按照建议启动了RewriteEngine,但仍然不走运,我还删除了缓存并以匿名方式打开浏览器以避免页面缓存,仍然没有重定向这不是[L]的方式标志起作用。一旦规则匹配,我会告诉重写引擎停止。在这种情况下,第一条规则没有匹配,因此不会触发L标志。此外,一旦url被重写,重写规则将针对新重写的url重新运行。1:我的注释的第一行是Apache文档的精确引用,2:pattern在您的规则中说:^(=如果以下内容在行的开头)并且您可能希望它说:只需匹配“在线市场开发(etc)”的每个实例。因此我认为在线市场开发(.*)(没有^and$)可以根据您的需要工作。这也不起作用。正如我所说,正上方相同格式(blog/blog)的规则确实起作用。同样,我认为您希望看到的内容已在第一个规则中处理,并且在该规则上使用L标志时,将停止进一步处理。