首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的.htaccess文件不是在wamp上工作(RewriteRule),而是在生产环境上工作。

问我的.htaccess文件不是在wamp上工作(RewriteRule),而是在生产环境上工作。
EN

Stack Overflow用户
提问于 2014-11-25 20:18:19
回答 2查看 245关注 0票数 1

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

代码语言:javascript
复制
# 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

当我-for示例-go到localhost/qtoon/contact.html时,它提供404 (将我重定向到wamp的主页),但是当我转到localhost/qtoon/index.php?action=contact时,它工作。

这个问题在生产环境中不存在(我指的是在线主机服务器)。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-25 21:39:02

您的规则似乎是正确的,但是RewriteBase似乎是问题所在,因为您的.htaccess位于子目录中。

请使用此RewriteBase:

代码语言:javascript
复制
RewriteBase /qtoon/
票数 1
EN

Stack Overflow用户

发布于 2014-11-25 20:43:40

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

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

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

虚拟主机配置的示例:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27135912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档