简体   繁体   English

如何将目录从根目录重写为子目录?

[英]How to rewrite directory from root to sub directory?

I am trying to rewrite my sub directory to root: 我试图将我的子目录重写为root:

forexample http://example.com/demo to http://example.com/img/demo here is my currunt htaccess file 例如http://example.com/demohttp://example.com/img/demo,这是我的当前htaccess文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /img/$1 [QSA,NC,L]

this works fine but it is changing url in browser, when I go to http://example.com/demo it redirects to http://example.com/img/demo/ and url changes in browser, How can I fix this? 这可以正常工作,但是它正在更改浏览器中的URL,当我转到http://example.com/demo时,它将重定向到http://example.com/img/demo/,并在浏览器中更改了URL,如何解决此问题?

Thanks 谢谢

You need to turn off the directory slash 您需要关闭目录斜杠

To fix this, Add the following line above RewriteEngine directive 要解决此问题,请在RewriteEngine指令上方添加以下行

DirectorySlash Off

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

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