douqiang4501 2017-03-01 20:34
浏览 29

htaccess将两个子目录重写为root

I have the following htaccess file:

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/site/v1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/v1/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ site/v1/ [L]

So when I access either domain.com or www.domain.com, I go directly to domain.com/site/v1, without the /site/v1 part showing on the browser.

But my problem is that inside the site/v1 folder, there's a admin folder, containing the website's CMS, and when I access domain.com/admin, it redirects to domain.com/site/v1/admin, with the /site/v1 part being displayed on the browser.

So, my question is, how I can get to access the /site/v1/admin folder without displaying all the path, i.e., when I access domain.com/admin, it access the subfolder, but doesn't display it?

In other format, I have:
- I access domain.com/about
- On the server side, I'm actually at domain.com/site/v1/about
- On my browser I see domain.com/about
- ps: about here is a parameter being passed to my back-end via a RewriteCond directive (on another piece of code), not being a folder (but it works just as well with a folder)

What I too have:
- I access domain.com/admin
- On the server side, I'm actually at domain.com/site/v1/admin
- On my browser I see domain.com/site/v1/admin

What I want:
- The last item before to be "I see domain.com/admin"

Thank you!

EDIT

Here's my full htaccess file after the changes:

# force ssl
RewriteEngine on
RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/site/v1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/v1/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^admin/$ /site/v1/admin/ [L]
RewriteRule ^(/)?$ site/v1/ [L]
  • 写回答

1条回答 默认 最新

  • duanpu2272 2017-03-01 21:57
    关注

    A simple way to rewrite the base url is to us a rewrite rule like this.

    RewriteRule ^$ /site/v1/ [L]
    

    To solve your admin directory issue, just add and additional rule like this.:

    RewriteRule ^admin/$ /site/v1/admin/ [L]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序