将所有请求发送到v1 / index.php - htaccess

时间:2015-12-14 14:09:35

标签: php .htaccess

我正在构建api并希望将所有请求重定向到v1 / index.php

我的文件夹结构是;

-htdocs
--v1
----index.php

这是我的htaccess atm

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

我希望发送到api.example.co.uk的所有请求都转到v1/index.php

2 个答案:

答案 0 :(得分:1)

  

我希望发送到api.example.co.uk的所有请求都转到v1/index.php

您可以在root .htaccess中使用此规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} =api.example.co.uk
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ v1/index.php [L]

答案 1 :(得分:0)

如果您将域名指向/htdocs/v1/文件夹,并将index.php.htaccess文件放在其中,则会将任何请求重定向到index.php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]