简体   繁体   English

重写URL以隐藏文件夹名称并在没有文件夹名称的情况下将其打开

[英]Url rewriting for hiding folder name and open it without folder name

I hv used all my uls in action with root directory now i cant change all of them so i need to rewrite my home url which hides folder name and if someone opens that domain then data saved in that folder must also be opened but folder name should not be displayed in url ie i have this 我将所有ul用于根目录,现在我无法更改所有ul,因此我需要重写隐藏文件夹名称的主url,如果有人打开该域,则还必须打开保存在该文件夹中的数据,但文件夹名称应不显示在URL即我有这个

http://example.com/foldername http://example.com/foldername

.I want to change this in as 我想将其更改为

http://example.com http://example.com

but it should automatically take foldername data .How this can be achieved by using ".htaccess" file 但是它应该自动获取文件夹名称数据。如何使用“ .htaccess”文件来实现

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

This is the .htaccess file i am currently using 这是我当前正在使用的.htaccess文件

Keep this rule in root .htaccess: 将此规则保留在root .htaccess中:

RewriteEngine On

RewriteRule ^(?!foldername/)(.*)$ foldername/$1 [L,NC]

Then have this simplified code in /fodlername/.htaccess : 然后在/fodlername/.htaccess使用以下简化代码:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Change your .htaccess file like this 像这样更改您的.htaccess文件

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /foldername/
RewriteCond %{HTTP_HOST} ^(www\.)?yoursite.com$
RewriteRule ^foldername/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?yoursite.com$
RewriteRule !^foldername/ foldername%{REQUEST_URI} [L]

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

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