url redirection working incorrect using .htacess in php

半世苍凉 提交于 2019-12-12 05:05:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!