I have a .htaccess
file in my virtual host which is configured in /etc/apache2/sites-enabled
and /etc/apache2/sites-available
like this:
<VirtualHost *:80>
DocumentRoot "/var/www/html/project/httpdocs"
ServerName project.localhost
ServerAdmin webmaster@project.localhost
<Directory /var/www/html/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
Allow From All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include conf-available/serve-cgi-bin.conf
</VirtualHost>
And my .htaccess
is:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# Some RewriteRules
RewriteRule ^api$ api.php
</IfModule>
So when I try to access any other RewriteRule address there is no problem at all, but then when I try to access project.localhost/api
I get a 404, being that I can access project.localhost/api.php
What am I doing wrong?
On htaccess context the pattern of RewriteRule
directive is relative to the directory the htaccess file is located in. so You need to remove the leading slash and use a relative path ^api$
instead of ^/api$
.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# Some RewriteRules
RewriteRule ^api$ api.php
</IfModule>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.