URL重定向工作不正确,在PHP中使用.htacess [英] url redirection working incorrect using .htacess in php

查看:88
本文介绍了URL重定向工作不正确,在PHP中使用.htacess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子域api.example.com。

I have one sub domain api.example.com.

我的代码在 / var / www / html / 文件夹。

我的所有子域都重定向到 / var / www / html 文件夹。

my all sub domain is redirect to /var/www/html folder.

我正在使用api.example.com重定向到 / var / www / html / api 文件夹。在

上使用 .htaccess

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]

但是问题是,它也更改了我的URL, api.example.com/api 我不想更改我的URL。

But the problem is, it is also change my url , api.example.com/api i don't want to change my URL.

当我在浏览器选项卡中键入 api.example.com 并按Enter时,它将更改为 api.example .com / api ,它是 api文件夹的打开的 index 文件,但我不知道不想更改我的URL,它将打开api文件夹的索引文件。

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.

推荐答案

将其更改为此

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.

这篇关于URL重定向工作不正确,在PHP中使用.htacess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆