简体   繁体   English

URL重定向工作不正确,在PHP中使用.htacess

[英]url redirection working incorrect using .htacess in php

I have one sub domain api.example.com. 我有一个子域api.example.com。

my code is on /var/www/html/ folder. 我的代码在/var/www/html/文件夹中。

my all sub domain is redirect to /var/www/html folder. 我的所有子域都重定向到/var/www/html文件夹。

I am use api.example.com to redirect on /var/www/html/api folder. 我正在使用api.example.com重定向到/var/www/html/api文件夹。 Using .htaccess 使用.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. 但是问题是,它也更改了我的url, api.example.com/api我不想更改我的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. 当我在浏览器选项卡中键入api.example.com并按Enter时,它将更改为api.example.com/api ,它是api folder打开index文件,但我不想更改我的URL,它将打开api文件夹的索引文件。

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. 如果这仍然不是您想要的,那么您将拥有一些其他规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM