Apache 重写规则/重写条件根本不起作用
首先,我知道这里有很多类似的问题,我可以向你保证,我一直在研究它们。我尝试过使用这里的答案进行大量的变化,但在花了整个上午的时间试图让它工作后,我放弃了,并寻求帮助 我的.htaccess文件中有以下条件和规则,但它们根本不起作用:Apache 重写规则/重写条件根本不起作用,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,首先,我知道这里有很多类似的问题,我可以向你保证,我一直在研究它们。我尝试过使用这里的答案进行大量的变化,但在花了整个上午的时间试图让它工作后,我放弃了,并寻求帮助 我的.htaccess文件中有以下条件和规则,但它们根本不起作用: # 301 --- http://www.example.com/ProjectSection.aspx?id=10 => http://example.com/projects/maintenance RewriteCond %{HTTP_HOST} ^ww
# 301 --- http://www.example.com/ProjectSection.aspx?id=10 => http://example.com/projects/maintenance
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{QUERY_STRING} (^|&)id=10($|&)
RewriteRule ^ProjectSection\.aspx$ http://example.com/services/maintenance/? [L,R=302]
# 301 --- http://www.example.com/ProjectSection.aspx => http://example.com/projects
RewriteRule ^ProjectSection\.aspx$ http://example.com/projects? [L,R=302]
当我访问www.example.com/ProjectSection.aspx时,我会看到一个404页面,其URL为。如果有人能帮我一点忙,我会非常感激的,我快疯了
这是完整的.htaccess文件(它是一个大的en),上面的代码放在底部
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
<FilesMatch "\.(gif|ico|jpe?g|png|svg|svgz|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
Options -MultiViews
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
<FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webapp|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
<IfModule mod_mime.c>
# Audio
AddType audio/mp4 m4a f4a f4b
AddType audio/ogg oga ogg
# JavaScript
# Normalize to standard type (it's sniffed in IE anyways):
# http://tools.ietf.org/html/rfc4329#section-7.2
AddType application/javascript js jsonp
AddType application/json json
# Video
AddType video/mp4 mp4 m4v f4v f4p
AddType video/ogg ogv
AddType video/webm webm
AddType video/x-flv flv
# Web fonts
AddType application/font-woff woff
AddType application/vnd.ms-fontobject eot
# Browsers usually ignore the font MIME types and sniff the content,
# however, Chrome shows a warning if other MIME types are used for the
# following fonts.
AddType application/x-font-ttf ttc ttf
AddType font/opentype otf
# Make SVGZ fonts work on iPad:
# https://twitter.com/FontSquirrel/status/14855840545
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
# Other
AddType application/octet-stream safariextz
AddType application/x-chrome-extension crx
AddType application/x-opera-extension oex
AddType application/x-shockwave-flash swf
AddType application/x-web-app-manifest+json webapp
AddType application/x-xpinstall xpi
AddType application/xml atom rdf rss xml
AddType image/webp webp
AddType image/x-icon ico
AddType text/cache-manifest appcache manifest
AddType text/vtt vtt
AddType text/x-component htc
AddType text/x-vcard vcf
</IfModule>
AddDefaultCharset utf-8
<IfModule mod_mime.c>
AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase /
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
<FilesMatch "(^#.*#|\.(bak|config|dist|fla|inc|ini|log|psd|sh|sql|sw[op])|~)$">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!)
ExpiresByType image/x-icon "access plus 1 week"
# HTML components (HTCs)
ExpiresByType text/x-component "access plus 1 month"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
# Manifest files
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Media
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# Web feeds
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
# Web fonts
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
Options +FollowSymLinks
RewriteEngine On
#启用重写引擎
# ------------------------------
重新启动发动机
重写基/
#重定向index.php请求
# ------------------------------
RewriteCond%{THE_REQUEST}^[^/]*/index\.php[NC]
RewriteCond%{THE_REQUEST}^GET
重写规则^index\.php(+)$1[R=301,L]
#标准表达式引擎重写
# ------------------------------
重写秒$1!\。(css | js | gif | jpe?g | png)[NC]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/index.php/$1[L]
SetEnvIf原点“:”是
标题集访问控制允许原点“*”env=IS\u CORS
标题集访问控制允许原点“*”
选项-多视图
标题集X-UA-兼容“IE=edge”
标题未设置X-UA-Compatible
#音频
AddType音频/mp4 m4a f4a f4b
AddType音频/ogg oga ogg
#JavaScript
#标准化为标准类型(它在IE中被嗅探):
# http://tools.ietf.org/html/rfc4329#section-7.2
AddType应用程序/javascript jsonp
AddType应用程序/json
#录像带
AddType视频/mp4 mp4 m4v f4v f4p
AddType视频/ogg ogv
AddType视频/webm webm
AddType视频/x-flv flv
#网页字体
AddType应用程序/font-woff-woff
AddType应用程序/vnd.ms-fontobject eot
#浏览器通常会忽略字体MIME类型并嗅探内容,
#但是,如果其他MIME类型用于
#以下字体。
AddType应用程序/x-font-ttf ttc ttf
AddType字体/opentype otf
#在iPad上使用SVGZ字体:
# https://twitter.com/FontSquirrel/status/14855840545
AddType image/svg+xml svg svgz
加法编码gzip svgz
#其他
AddType应用程序/八进制流safariextz
AddType应用程序/x-chrome-extension crx
AddType应用程序/x-opera-extension oex
AddType应用程序/x-shockwave-flash swf
AddType应用程序/x-web-app-manifest+json webapp
AddType应用程序/x-xpinstall xpi
AddType应用程序/xml原子rdf rss xml
AddType图像/webp webp
AddType图像/x图标图标图标
AddType文本/缓存清单appcache清单
AddType文本/vtt vtt
AddType文本/x组件htc
AddType text/x-vcard vcf
AddDefaultCharset utf-8
AddCharset utf-8.atom.css.js.json.rss.vtt.webapp.xml
选项+FollowSymlinks
#选项+符号链接所有者匹配
重新启动发动机
#重写基/
重写cond%{HTTPS}=在…上
重写cond%{HTTP_HOST}^www\.(.+)$[NC]
重写规则^http://%1%{REQUEST_URI}[R=301,L]
选项-索引
重写cond%{SCRIPT_FILENAME}-d[或]
重写cond%{SCRIPT_FILENAME}-f
重写规则“(^ |/)\”-[F]
命令允许,拒绝
全盘否定
满足所有
SetEnvIfNoCase^((gzip | deflate)\s*,?\s*)+|[X~-]{4,13}$有接受编码
RequestHeader追加接受编码“gzip,deflate”env=HAVE_Accept-Encoding
AddOutputFilterByType DEFLATE应用程序/atom+xml\
应用程序/javascript\
应用程序/json\
application/rss+xml\
应用程序/vnd.ms-fontobject\
应用程序/x-font-ttf\
application/x-web-app-manifest+json\
application/xhtml+xml\
应用程序/xml\
字体/开放式\
image/svg+xml\
图像/x图标\
文本/css\
文本/html\
文本/纯文本\
文本/x组件\
文本/xml
标题未设置ETag
FileTag无
过期于
ExpiresDefault“访问加1个月”
#CSS
ExpiresByType文本/css“访问加1年”
#数据交换
ExpiresByType应用程序/json“访问加0秒”
ExpiresByType应用程序/xml“访问加0秒”
ExpiresByType text/xml“访问加0秒”
#Favicon(无法重命名!)
ExpiresByType图像/x图标“访问”
# 301 --- http://www.example.com/ProjectSection.aspx?id=10 => http://example.com/projects/maintenance
RewriteCond %{QUERY_STRING} (^|&)id=10($|&)
RewriteRule ^(.*)/ProjectSection\.aspx$ http://example.com/services/maintenance/? [L,R=302]
# 301 --- http://www.example.com/ProjectSection.aspx => http://example.com/projects
RewriteRule ^(.*)/ProjectSection\.aspx http://example.com/projects? [L,R=302]