[英]Apache2 rewrite rule to remove index.php from URL (Slim Framework)
I have a project in slim framework where my folder structure is like this: 我在苗条的框架中有一个项目,我的文件夹结构是这样的:
root web directory
--project
-----api
-----vendor
-----index.php
-----.htaccess
Now, my problem is that I want to remove index.php from my API URLs so that I can have something like http://127.0.0.1/project/api/test instead of http://127.0.0.1/project/api/index.php/test . 现在,我的问题是我想从我的API网址中删除index.php,以便可以使用类似http://127.0.0.1/project/api/test的内容,而不是http://127.0.0.1/project/api /index.php/test 。 My .htaccess looks like this but doesn't work: RewriteEngine On
我的.htaccess看起来像这样,但是不起作用:RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
This should work for you. 这应该为您工作。
RewriteEngine On
RewriteRule ^api/([^/]*)$ /project/api/index.php?value=$1 [L]
Use this in your Root/.htaccess
file 在您的
Root/.htaccess
文件中使用它
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/api/(.*)/?$ /project/api/index.php/$1 [QSA,NC,L]
Thanks guys but this worked for me: 谢谢大家,但这对我有用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
Hope it helps someone else too... 希望它也能帮助别人...
I performed the following steps to make it work on Ubuntu standalone server. 我执行了以下步骤以使其在Ubuntu独立服务器上工作。
Step 1 - you have to enable rewrite mod 步骤1-您必须启用重写Mod
a2enmod rewrite
Step 2 - make sure your apache settings in /etc/apache2/apache2.conf as follow 第2步 -确保您在/etc/apache2/apache2.conf中的apache设置如下
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
Make sure All Override should be all 确保所有替代都应全部
Step 3 - Create .htaccess file with following 第3步 -创建具有以下内容的.htaccess文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.