使用完全相同的.htaccess文件,我的本地LAMP服务器(通过mamp pro)和生产服务器的行为不同。我想有一个不同的配置,但哪一个?
在我的本地服务器上,http://domain.com/section/item/正确地重定向到http://domain.com/index.php?section= $ 1& item = $ 2
在我的生产服务器上,http://domain.com/section/item/可以访问http://domain.com/section/item/index.html
如何使生产服务器的行为与开发服务器相似?
以下是htaccess文件内容以防万一。
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
#--------------------------------------------
# PRETTY URLS
#--------------------------------------------
# if the following conditions are met, SKIP the rewriteRules.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]
# Externally redirect to add missing trailing slash
RewriteRule [^/]$ %{REQUEST_URI}/ [R,L]
# SIX PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&title=$6 [NC,L,QSA]
# FIVE PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?section=$1&item=$2&menu=$3&content=$4&id=$5 [NC,L,QSA]
# FOUR PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?section=$1&item=$2&menu=$3&content=$4 [QSA,L]
# THREE PARAMS : projects/touch/texts/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?section=$1&item=$2&menu=$3 [QSA,L]
# TWO PARAMS: downloads
RewriteRule ^downloads/([^/]+)/$ index.php?section=downloads&item=$1 [QSA,L]
# TWO PARAMS:
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?section=$1&item=$2 [QSA,L]
# TAG URL : index.php?tag=url+encoded+keyword
RewriteRule ^tag/([\w-]+)/$ index.php?tag=$1 [NC,L,QSA]
# ONE PARAM
RewriteRule ^([\w-]+)/$ index.php?section=$1 [L,QSA]
#--------------------------------------------
# END PRETTY URLS
#--------------------------------------------
</IfModule>
答案 0 :(得分:0)
尝试进行2次更改。
在.htaccess文件的顶部添加此行:
DirectoryIndex index.php
然后将您的第一条规则更改为:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
编辑:也可以尝试:
Options +FollowSymLinks -MultiViews
答案 1 :(得分:0)
是的,两个文件目录结构完全相同
我不知道你是如何完成所有设置的,但是可能加载的模块的顺序在开发和生产(长镜头)之间是不同的,这可能会影响订单模块正在URL处理管道中应用。 mod_autoindex或mod_dir之类的顺序或类似内容因此导致/section/item/
的请求在 mod_rewrite有机会做任何事情之前被解析为/section/item/index.html
。这意味着这种情况变为现实:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]
并且您的其他规则都不会被应用,因此/section/item/index.html
会被提供。
至于如何解决这样的问题,我想你可以尝试关闭服务器配置中的目录索引(通过将其注释掉,无处不在),或者将其设置为在获取服务的目录中不存在的内容:
DirectoryIndex _index.php