我使用vagrant和virtualBox建立了一个本地环境,
我在.htaccess
(在生产代码中工作)中的一些规则将触发404错误,当在生产环境中完美地工作时
这个例如有效:
# hostname/posts/?show=lasts -> posts.php?show=lasts
RewriteRule ^posts/$ posts.php?$1&friendly=1 [QSA]
无效(404):
# hostname/page/the-title/5 -> page.php?id=5
RewriteRule ^page/(.+)/(.+) page.php?id=$2&friendly=1
知道我缺少什么吗?
生产中的主机名就像page.com
,虚拟机中的主机名是localhost:8085
以防万一
- 编辑 -
完整区块:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)%20(.*)$
RewriteRule ^(.*)$ /$1?%1-%2 [L,R=301,NE]
ErrorDocument 500 /oohps.php
ErrorDocument 404 /where.php
RewriteBase /
# Quitar www
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# Canonicación de la IP
RewriteCond %{HTTP_HOST} ^70.XX.XX.XXX [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^s158783.gridserver.com$
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^new.domain.com$
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^beta.domain.com$
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
# URLS amigables
RewriteRule ^page/(.+)/(.+) page.php?id=$2&friendly=1
RewriteRule ^pregunta/(.+)/(.+) pregunta.php?id=$2&friendly=1
RewriteRule ^new/(.+)/(.+) new.php?id=$2&friendly=1
RewriteRule ^user/(.+)/(.+) user.php?que=user&id=$2&friendly=1
RewriteRule ^pages-de-cocina/$ pages.php?$1&friendly=1 [QSA]
RewriteRule ^pages/(.+)/(.+) pages.php?que=cat&f=$2&friendly=1 [QSA]
失败的网址:
/page/the-title/4
/user/the-name/6
答案 0 :(得分:2)
保持这样的规则:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^posts/(.*)$ posts.php?$1&friendly=1 [L,QSA,NC]
RewriteRule ^page/[^/]+/(.*)$ page.php?id=$1&friendly=1 [L,QSA,NC]