繁体   English   中英

我的.htaccess文件在wamp上不起作用(RewriteRule),但在生产环境上起作用

[英]my .htaccess file is not working (RewriteRule) on wamp but working on production environment

这是我的.htaccess文件的内容:

# Use PHP5 Single php.ini as default
#AddHandler application/x-httpd-php5s .php

RewriteEngine on

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

RewriteRule ^about.html$ index.php?action=about
RewriteRule ^audioCats.html$ index.php?action=viewCat&catId=0&type=audio
RewriteRule ^videoCats.html$ index.php?action=viewCat&catId=0&type=video
RewriteRule ^audioCat_([0-9]+).html$ index.php?action=viewCat&catId=$1&type=audio
RewriteRule ^videoCat_([0-9]+).html$ index.php?action=viewCat&catId=$1&type=video
RewriteRule ^blog.html$ index.php?action=viewCat&catId=0&type=blog&pageId=0
RewriteRule ^blog_([0-9]+).html$ index.php?action=blog&id=$1
#RewriteRule ^blog_([0-9]+).html$ index.php?action=viewCat&catId=0&type=blog&pageId=0
RewriteRule ^blogCat_([0-9]+).html$ index.php?action=viewCat&catId=$1&type=blog&pageId=0
RewriteRule ^blogCat_([0-9]+)_([0-9]+).html$ index.    php?action=viewCat&catId=$1&type=blog&pageId=$2
RewriteRule ^articlesCat_([0-9]+).html$ index.    php?action=viewCat&catId=$1&type=articles&pageId=0
RewriteRule ^articlesCat_([0-9]+)_([0-9]+).html$ index.    php?action=viewCat&catId=$1&type=articles&pageId=$2
RewriteRule ^articles_([0-9]+).html$ index.php?action=articles&id=$1


RewriteRule ^(.*)Rating.html$ index.php?action=rateIt&itemType=$1

RewriteRule ^videoRating.html$ index.php?action=rateIt&itemType=video
RewriteRule ^video([0-9]+).html$ index.php?action=video&id=$1
RewriteRule ^audio([0-9]+).html$ index.php?action=audio&id=$1
RewriteRule ^eps([0-9]+).html$ index.php?action=eps&id=$1

RewriteRule ^logActivity.html$ index.php?action=logActivity
RewriteRule ^search.html$ index.php?action=search

#Comments
RewriteRule ^addComment.html$ index.php?action=addComment
RewriteRule ^voteForComment.html$ index.php?action=voteForComment
RewriteRule ^fetchComment.html$ index.php?action=fetchComment
RewriteRule ^moreComments.html$ index.php?action=fetchMoreComments
#End Comments
RewriteRule ^fetchVideoUrl.html$ index.php?action=fetchVideoUrl
RewriteRule ^register.html$ index.php?action=register
RewriteRule ^editAccount.html$ index.php?action=editAccount
RewriteRule ^login.html$ index.php?action=login
RewriteRule ^ajaxLogin.html$ index.php?action=login&ajax=true
RewriteRule ^inbox.html$ index.php?action=inbox
RewriteRule ^sendSeries.html$ index.php?action=sendSeries&catId=0
RewriteRule ^logout.html$ index.php?action=logout
RewriteRule ^profile.html$ index.php?action=profile
RewriteRule ^profile([0-9]+).html$ index.php?action=profile&userId=$1
RewriteRule ^sendMessage([0-9]+).html$ index.php?action=sendMessage&userId=$1
RewriteRule ^friendRequest([0-9]+).html$ index.php?action=friendRequest&userId=$1
RewriteRule ^friendApprove([0-9]+).html$ index.php?action=friendApprove&userId=$1
RewriteRule ^friendDeny([0-9]+).html$ index.php?action=friendDeny&userId=$1
RewriteRule ^updateAudioListen.html$ index.php?action=updateAudioListen
RewriteRule ^downloads/([0-9]+)/(.*)/?$ index.php?action=download&id=$1&hash=$2
RewriteRule ^vote.html$ index.php?action=vote
RewriteRule ^contact.html$ index.php?action=contact
RewriteRule ^mailList.html$ index.php?action=maillist
RewriteRule ^friendRequests.html$ index.php?action=friendRequests
RewriteRule ^index.html$ index.php
RewriteRule ^rss$ index.php?action=rss
RewriteRule ^rss/(.*)$ index.php?action=rss&keyword=$1
RewriteRule ^sitemap.xml$ index.php?action=sitemap

RewriteRule ^cartoon.html$ index.php?action=cartoon&pageId=0
RewriteRule ^cartoon_page_([0-9]+).html$ index.php?action=cartoon&pageId=$1
RewriteRule ^cartoon_([0-9]+).html$ index.php?action=cartoon&id=$1

RewriteRule ^colors.css$ css.php

RewriteRule ^deleteMessage_([0-9]+).html$ index.php?action=deleteMessage&id=$1
RewriteRule ^readMessage_([0-9]+).html$ index.php?action=readMessage&id=$1
RewriteRule ^monitorMessage_([0-9]+).html$ index.php?action=monitoringMessage&lastCount=$1

当我-例如-转到localhost / qtoon / contact.html时,它给出404(将我重定向到wamp的主页),但是当我转到localhost / qtoon / index.php?action = contact时,它可以工作..

生产环境中不存在此问题(我的意思是在线托管服务器上)

您的规则似乎正确,但由于您的.htaccess位于RewriteBase ,因此RewriteBase似乎是问题所在。

请改用以下RewriteBase

RewriteBase /qtoon/

404看起来像RewriteBase /的组合,并且在域的子目录(即http://localhost/exampleProj/ )内工作。

这是因为/将强制apache将请求重写为http://localhost/index.php

解决方案是删除RewriteBase /或设置虚拟主机。 您可以在Apache配置文件和/ etc / hosts文件中设置虚拟主机(我相信它在Windows上的drivers \\ etc下的系统文件夹中)。

虚拟主机配置的示例:

http://httpd.apache.org/docs/2.2/vhosts/examples.html#twoips

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM