我正在使用PHP开发API系统,但我不希望这些URL包含文件扩展名。因此,我创建了一个包含以下内容的.htaccess文件:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://xxxxx.com/api/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://xxxxx.com/api/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
打开http://xxxxx.com/api/some_call.php时,它会将我重定向到http://xxxxx.com/api/some_call,但我收到404错误的错误:
The requested URL /api/some_call was not found on this server.
我可以完全控制(root)服务器,因此欢迎任何建议。
提前致谢,
CrushedPixel
答案 0 :(得分:1)
尝试添加条件
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ $1.php [L]
然后尝试在Options -Multiviews
RewriteEngine On