mod_rewrite指令独立工作,但不能在具有完整htaccess文件的情况下使用concrete5
问题描述:
我无法使用某些mod_rewrite指令来修改站点的htaccess文件我知道隔离但不在完整的htaccess文件的上下文中工作。该网站的CMS是Concrete5,所以在htaccess文件中有一些具体的Concrete5配置。mod_rewrite指令独立工作,但不能在具有完整htaccess文件的情况下使用concrete5
我试图重写格式的URLS
http://www.mywebsite.com/proplist/?location=town&distance=3&proptype=buy&maxPrice=&minPrice=&bedrooms=&propertyType=
到
http://www.mywebsite.com/property/town/buy/
我有下面的指令独立工作(其中我在一个文件夹,名为proplist这样创建下的index.php在另一个网站服务器的根目录):
RewriteBase /proplist
RewriteRule property/([a-zA-z]+)/([a-zA-z]+)/$ http://www.mywebsite.com/property/\/?location=$1&distance=3&proptype=$2&maxPrice=&minPrice=&bedrooms=&propertyType= [R]
Redirect 301 /property/ http://www.mywebsite.com/proplist/
(我想我可以使用%{} REQUEST_FILENAME在的http://www.mywebsite.com
代替)
我不能得到上述的htaccess文件的背景下,已经到位这是(我的ammendments)工作:
<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
上述结果是如http://www.mywebsite.com/property/woking/buy/
的网址被重定向到http://www.mywebsite.com/index.php
任何人都可以帮忙吗?
答
您需要做的第一件事是将所有的属性搜索URL规则之前的concrete5路由规则。路由规则完全破坏了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 --
到:
# -- 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 --
但我真的不知道什么样的你原来的规则的点分别。他们是mod_alias和mod_rewrite的组合,肯定是一团糟。如果您实际上想要重定向而不是重写(这是您要求的,重写不是重定向),请将标志从[L]
更改为[L,R=301]
。所以这两条规则需要在重定向到www
的那条下面。
当网站没有访问者时,请尝试并实施您的建议,Jon,今天晚上。它看起来很有希望并且被赞赏。将报告结果。 – Phil
我确认Jon的解决方案有效,我非常感谢。这正在改写我想要的 - 不需要重定向。 – Phil