如何使用 htaccess 从 url 中删除文件夹名称 [英] how to remove folder name from url using htaccess
问题描述
我想更改以下网址:
http://domain.com/Portfolios/iPhone/app
致:
http://domain.com/iPhone/app
对于所有网址都一样:
domain.com/Portfolios/iPad/app
致:
domain.com/iPad/app
来自:
domain.com/Portfolios/xyz/app
致:
domain.com/xyz/app
我尝试了很多,但没有任何效果,所以请帮助我.
I have tried a lot but nothing is working for me, so please help me.
当我需要帮助时,为什么任何朋友都拒绝投票,如果您知道答案,请回答.
When I need help why any buddy down voting it, if you know the answer then answer it.
更新
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^Portfolios(/.*|)$ $1 [L,NC]
</IfModule>
推荐答案
Enable mod_rewrite
和 .htaccess
通过 httpd.conf
然后把此代码位于 DOCUMENT_ROOT
目录下的 .htaccess
目录:
Enable mod_rewrite
and .htaccess
through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^Portfolios/(.*)$ /$1 [L,NC,R]
说明:以上规则是匹配以Portfolios
开头的URL模式,并且有类似/Portfolios/xyz/app
的东西,并把$1
中的 >xyz/app.它使外部重定向到 /$1
,即 /xyz/app
.
Explanation: Above rules is matching URL patter that starts with Portfolios
and have somthing like /Portfolios/xyz/app
and puts xyz/app
in $1
. It makes an external redirection to /$1
i.e. /xyz/app
.
这些是使用的标志:
L - Last
NC - Ignore (No) Case comparison
R - External redirection (with 302) -- can be changed to R=301
这篇关于如何使用 htaccess 从 url 中删除文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!