简体   繁体   English

使用mod_rewrite htaccess隐藏子文件夹

[英]hide subfolder using mod_rewrite htaccess

how can i hide project subfolder in the two url's, i have tried many ways but nothing went fine 我如何隐藏两个URL中的项目子文件夹,我尝试了很多方法,但是没有任何问题

below are the url's 以下是网址的

mydomain.com/project/service.php?param=40&some/text/goes/here

and

mydomain.com/project/item.php?param=15&some/text/goes/here

this is the code i have tried so far. 这是我到目前为止尝试过的代码。

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_URI} !^/project/.*$
RewriteRule ^(.*)$ /project/$1 [L,QSA]
</IfModule>

Any help would be so much appreciated, Thanks! 任何帮助将不胜感激,谢谢!

This should work: 这应该工作:

 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_URI} ^/project/
 RewriteRule ^project/(.*)$ /$1 [r,L]

 RewriteCond %{REQUEST_URI} !^/project/.*$
 RewriteRule ^(.*)$ /project/$1 [L]

This will remove the project folder in the URL, and then add it back silently (the user doesn't see it being readded. 这将删除URL中的project文件夹,然后以静默方式将其重新添加(用户看不到它已被读取。

I've rewritten your htaccess taking your comments into consideration 考虑到您的评论,我已经重写了您的htaccess

Options +FollowSymLinks -MultiViews -Indexes

RewriteEngine on
RewriteBase /

# hide PROJECT folder from url
RewriteCond %{THE_REQUEST} \ /project/(.*)\ HTTP/ [NC]
RewriteRule . %1 [R=301,L]

# hide homepage index.php
RewriteCond %{THE_REQUEST} \ /index\.php [NC]
RewriteRule . / [R=301,L]

# check if file/folder exists in PROJECT folder (if so, internally rewrite)
RewriteCond %{DOCUMENT_ROOT}/project%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/project%{REQUEST_URI} -d
RewriteRule ^(.*)$ project/$1 [L,QSA]

# internally rewrite everything (except existing file/folder) to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

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

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