简体   繁体   English

Apache RewriteRule模式不起作用

[英]Apache RewriteRule mode not working

I wanna rewrite rule in order to allow ability the path like this: 我想重写规则以允许能力这样的路径:

http://example.com/api/somemethod/ Api is an api.php file that contains api class. http://example.com/api/somemethod/ Api是一个包含api类的api.php文件。

I've rewritten rules in .htaccess, but if i try to link above, i got an error: 我已经在.htaccess中重写了规则,但是如果尝试在上面进行链接,则会出现错误:

Object not found! The requested URL was not found on this server. If
you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404

Here is my .htaccess file: 这是我的.htaccess文件:

RewriteEngine On RewriteEngine开

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?x=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]

Since I can't yet comment on the question (yay karma), I will post one of the more common answers, as this is usually caused by the .htaccess file not being read/followed: 由于我尚无法对此问题发表评论(是,因果报应),因此,我将发布较为常见的答案之一,因为这通常是由于未读取/关注.htaccess文件引起的:

"try putting junk in your htaccess file. If it's being read, you will get an Internal Server Error when accessing that resource. If it doesn't cause an Internal Server Error, see AllowOverride. This won't work from 2.4 if AllowOverride is used with Nonfatal" “尝试将垃圾放入htaccess文件中。如果正在读取它,则在访问该资源时会收到内部服务器错误消息。如果它不会引起内部服务器错误,请参阅AllowOverride。如果AllowOverride为与Nonfatal一起使用”

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

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