Apache mod_rewrite指令独立工作,但不能在使用concrete5的完整htaccess文件的上下文中工作

Apache mod_rewrite指令独立工作,但不能在使用concrete5的完整htaccess文件的上下文中工作,apache,.htaccess,mod-rewrite,concrete5,Apache,.htaccess,Mod Rewrite,Concrete5,我很难用一些mod_重写指令来编辑站点的htaccess文件,我知道这些指令是独立工作的,但不是在完整htaccess文件的上下文中。该站点的CMS是Concrete5,因此htaccess文件中有一些关于Concrete5配置的细节 我正在尝试重写格式的URL http://www.mywebsite.com/proplist/?location=town&distance=3&proptype=buy&maxPrice=&minPrice=&bedro

我很难用一些mod_重写指令来编辑站点的htaccess文件,我知道这些指令是独立工作的,但不是在完整htaccess文件的上下文中。该站点的CMS是Concrete5,因此htaccess文件中有一些关于Concrete5配置的细节

我正在尝试重写格式的URL

http://www.mywebsite.com/proplist/?location=town&distance=3&proptype=buy&maxPrice=&minPrice=&bedrooms=&propertyType=

我得到了以下独立工作的指令(我在另一个Web服务器的webroot下的名为proplist的文件夹中创建了index.php):

(我想我可以使用%{REQUEST\u FILENAME}而不是
http://www.mywebsite.com

我无法在已经存在的htaccess文件的上下文中使用上述内容,该文件是(使用我的amendments):


重新启动发动机
#
#--从5个URL开始--
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}/index.html-F
重写cond%{REQUEST_FILENAME}/index.php-F
重写规则。index.php[L]
#--结束--
重新启动发动机
重写cond%{HTTP_HOST}^www\。
重写规则^(.*)$http://www.%{HTTP_HOST}/$1[R=301,L]
#--重写属性搜索URL--
重写基本/项目列表
重写cond%{REQUEST_URI}属性
重写规则属性/([a-zA-z]+)/([a-zA-z]+)/$http://www.mywebsite.com/proplist/\/位置=$1,距离=3,属性类型=$2,最大价格=&minPrice=&Beddrooms=&propertyType=[R]
重定向301/property/%{REQUEST_FILENAME}/proplist/
重写基/
#--结束重写属性搜索URL--
#Gzip
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css应用程序/x-javascript应用程序/javascript text/javascript
#结束Gzip
#删除浏览器错误
浏览器匹配^Mozilla/4 gzip纯文本/html
浏览器匹配^Mozilla/4\.0[678]无gzip
BrowserMatch\bMSIE!没有gzip!仅限gzip文本/html
头附加用户代理
##过期缓存##
过期于
过期按类型映像/jpg“访问加1年”
过期按类型图像/jpeg“访问加1年”
ExpiresByType image/gif“访问加1年”
过期按类型图像/png“访问加1年”
ExpiresByType文本/css“访问加1个月”
过期按类型应用程序/pdf“访问加1个月”
ExpiresByType text/x-javascript“访问加1个月”
过期按类型应用程序/x-shockwave-flash“访问加1个月”
过期按类型图像/x图标“访问加1年”
ExpiresDefault“访问加1周”
##过期缓存##
AddType应用程序/font-wof.woff
AddType应用程序/x-font-woff.woff
AddType应用程序/x-woff.woff
#完全访问文件结束
上面的结果是URL,例如
http://www.mywebsite.com/property/woking/buy/
被重定向到
http://www.mywebsite.com/index.php


有人能帮忙吗?

您需要做的第一件事是将所有属性搜索URL规则放在具体的路由规则之前。路由规则完全破坏了URI,当发生重定向时,被破坏的URI最终会被重定向

这意味着这些规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
必须在CMS规则之前

您可能还希望更改以下规则:

# -- rewrite property search urls --
RewriteBase /proplist
RewriteCond %{REQUEST_URI} property
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/proplist/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ %{REQUEST_FILENAME}/proplist/
RewriteBase /
# -- end rewrite property search urls --
致:


但我不确定你最初的规则是什么意思。它们是mod_别名和mod_重写的混合体,这肯定是一团混乱。如果您确实希望重定向而不是重写(这是您要求的,重写不是重定向),请将标志从
[L]
更改为
[L,R=301]
。因此,这两条规则需要在重定向到
www

的规则的正下方。Jon,今晚当网站的访问者很少时,它将尝试执行您的建议。这看起来很有希望,值得赞赏。我确认Jon的解决方案有效,我非常感谢。这是我想要的重写-不需要重定向。
<IfModule mod_rewrite.c>
RewriteEngine On
#
# -- concrete5 urls start --
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
# -- concrete5 urls end --

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# -- rewrite property search urls --
RewriteBase /proplist
RewriteCond %{REQUEST_URI} property
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/proplist/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ %{REQUEST_FILENAME}/proplist/
RewriteBase /
# -- end rewrite property search urls --

#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
#End Gzip

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 week"
</IfModule>

## EXPIRES CACHING ##
AddType application/font-wof          .woff
AddType application/x-font-woff       .woff
AddType application/x-woff            .woff

# end of full htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# -- rewrite property search urls --
RewriteBase /proplist
RewriteCond %{REQUEST_URI} property
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/proplist/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ %{REQUEST_FILENAME}/proplist/
RewriteBase /
# -- end rewrite property search urls --
# -- rewrite property search urls --
RewriteRule ^property/([a-zA-z]+)/([a-zA-z]+)/$ /proplist/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [L]
RewriteRule ^property/$ /proplist/ [L]
# -- end rewrite property search urls --