使用.htaccess将URI重定向到PHP文件

使用.htaccess将URI重定向到PHP文件,php,apache,.htaccess,Php,Apache,.htaccess,我在站点的根目录中有下面的.htaccess文件 Options +FollowSymLinks RewriteEngine On AddEncoding gzip .gz AddEncoding gzip .gzip <FilesMatch "\.(js.gz|js.gzip)$"> ForceType text/javascript </FilesMatch> <FilesMatch "\.(css.gz|css.gzip)$"> ForceTy

我在站点的根目录中有下面的.htaccess文件

Options +FollowSymLinks
RewriteEngine On

AddEncoding gzip .gz
AddEncoding gzip .gzip
<FilesMatch "\.(js.gz|js.gzip)$">
  ForceType text/javascript
</FilesMatch>
<FilesMatch "\.(css.gz|css.gzip)$">
  ForceType text/css
</FilesMatch>


RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
我的要求是,当用户转到www.mysite.com/api时,应该将其路由到上述目录结构中的api.php。阅读各种.htaccess指南时,我真的很困惑


如何将URI映射到特定的php文件?提前谢谢。

这就是你要找的吗

Options +FollowSymLinks
RewriteEngine On

AddEncoding gzip .gz
AddEncoding gzip .gzip
<FilesMatch "\.(js.gz|js.gzip)$">
  ForceType text/javascript
</FilesMatch>
<FilesMatch "\.(css.gz|css.gzip)$">
  ForceType text/css
</FilesMatch>

RewriteCond %{REQUEST_URI} ^/api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ow_plugin/service/controller/api.php [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
Options+FollowSymLinks
重新启动发动机
AddEncoding gzip.gz
AddEncoding gzip.gzip
ForceType文本/javascript
强制类型文本/css
重写cond%{REQUEST_URI}^/api
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$/ow_plugin/service/controller/api.php[L]
重写cond%{REQUEST_URI}^/索引\.php
重写cond%{REQUEST_URI}/OWU更新/索引\.php
重写cond%{REQUEST_URI}/ow_更新/
重写cond%{REQUEST_URI}/ow_cron/run\.php
重写cond%{REQUEST|u URI}(/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$[NC]
重写规则(.*)index.php

api.php的URI目前是什么?我还没有定义任何路由,因为如果定义了任何不同的URI,Oxwall api将限制路由。我只想直接路由到那个php文件。映射它是什么意思?您需要调用什么/api,然后重定向到api.php?是的,先生。我的意思是说“重定向”。这是指向api的正确路径吗?如果在浏览器中转到该文件,它是否工作?
Options +FollowSymLinks
RewriteEngine On

AddEncoding gzip .gz
AddEncoding gzip .gzip
<FilesMatch "\.(js.gz|js.gzip)$">
  ForceType text/javascript
</FilesMatch>
<FilesMatch "\.(css.gz|css.gzip)$">
  ForceType text/css
</FilesMatch>

RewriteCond %{REQUEST_URI} ^/api
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ow_plugin/service/controller/api.php [L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php