这是我的.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
当我 - 例如-go到localhost / qtoon / contact.html它给404(重定向我到wamp的主页)但是当我去localhost / qtoon / index.php?action = contact它工作.. < / p>
生产环境中不存在问题(我的意思是在线托管服务器上)
答案 0 :(得分:1)
您的规则似乎是正确的,但RewriteBase
似乎是问题,因为.htaccess位于子目录中。
改为使用此RewriteBase
:
RewriteBase /qtoon/
答案 1 :(得分:0)
404看似RewriteBase /
的组合,并在域的子目录中工作(即http://localhost/exampleProj/
)。
这是因为/
会强制apache将请求重写为http://localhost/index.php
。
解决方案是删除RewriteBase /
或设置虚拟主机。您可以在Apache配置文件和/ etc / hosts文件中设置虚拟主机(我相信它位于Windows上驱动程序\等下的系统文件夹中)。
虚拟主机配置的示例:
http://httpd.apache.org/docs/2.2/vhosts/examples.html#twoips