问题
I have one sub domain api.example.com.
my code is on /var/www/html/
folder.
my all sub domain is redirect to /var/www/html
folder.
I am use api.example.com to redirect on /var/www/html/api
folder. Using .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^api\. [NC]
RewriteRule !^api/ api%{REQUEST_URI} [L,NC]
But the problem is, it is also change my url , api.example.com/api
i don't want to change my URL.
when i type api.example.com
in browser tab and press enter then it is change into the api.example.com/api
and it is open index
file of api folder
but i don't want to change my URL and it will open index file of api folder.
回答1:
Change it to this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^api\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?api(/.*)?$ [NC]
RewriteRule ^/?(.*)/?$ /api/$1 [L,NC]
Notice
Delete you Browser Cache before you test. If this still so not what you want, than you have somwere some other rule in place.
来源:https://stackoverflow.com/questions/46709724/url-redirection-working-incorrect-using-htacess-in-php