Php 使用重写规则重定向文件夹

Php 使用重写规则重定向文件夹,php,wordpress,.htaccess,Php,Wordpress,.htaccess,我有一组URL,如下所示: 现在我想将url中带有/unternehman-2-2的所有url重定向到页面http://www.immvestwolf.de/unternehmen/ 我尝试了几种解决方案,但都不起作用,例如: 重写规则unternehmen-2-2/(.*)/unternehmen/[L,R=301] 或 重写规则^unternehmen-2-2/unternehmen/[L,R=301,NC] 有人有主意吗 以下是我的访问权限: 重新启动发动机 重写基/ 重写

我有一组URL,如下所示:

现在我想将url中带有
/unternehman-2-2
的所有url重定向到页面
http://www.immvestwolf.de/unternehmen/

我尝试了几种解决方案,但都不起作用,例如:

重写规则unternehmen-2-2/(.*)/unternehmen/[L,R=301]

重写规则^unternehmen-2-2/unternehmen/[L,R=301,NC]
有人有主意吗

以下是我的访问权限:


重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}!(.*)/$
重写规则^(.*)/[0-9]+$%{REQUEST_URI}/[QSA,L,R=301]
重写规则^expose/(*)$content/index.php?content=expose&query=$1[L,QSA]
#重写规则unternehman-2-2/(*)unternehman/[L,R=301]
#重写规则^unternehmen/darstellung/(*)$content/index.php?
content=unternehmen/darstellung&query=$1[L,QSA]
#重写规则^unternehmen/team/(.*)$content/index.php?
content=unternehmen/team&query=$1[L,QSA]
#重写规则^unternehmen/referencen/(.*)$content/index.php?
content=unternehmen/referencen&query=$1[L,QSA]
#重写规则^unternehmen/partner/(.*)$content/index.php?
content=unternehmen/partner&query=$1[L,QSA]
#重写规则^unternehmen/karriere/(*)$content/index.php?
content=unternehmen/karriere&query=$1[L,QSA]
#重写规则^unternehmen/verbundpartner/(*)$content/index.php?
content=unternehmen/verbundpartner&query=$1[L,QSA]
#重写规则^unternehmen/$content/index.php?content=unternehmen&query=$1
[L,QSA]
#重写规则^unternehmen/(.*)$content/index.php?
内容=卸载和查询=$1[L,QSA]
#重写规则^hausverwaltung/(.*)$content/index.php?
content=hausverwaltung&query=1美元[L,QSA]
#重写规则^investment/(*)$content/index.php?content=investment&query=$1
[L,QSA]
#重写规则^kontakt/(*)$content/index.php?content=kontakt&query=$1
[L,QSA]
#重写规则^kontakt2/(*)$content/index.php?content=kontakt2&query=$1
[L,QSA]
#重写规则^verietung/angebote/(.*)$content/index.php?
content=verietung/angebote&query=$1[L,QSA]
#重写规则^eigentum/angebote/(.*)$content/index.php?
content=eigentum/angebote&query=$1[L,QSA]
#重写规则^service/verietung/(*)$content/index.php?
内容=服务/害虫和查询=$1[L,QSA]
#重写规则^service/eigentum/(.*)$content/index.php?
内容=服务/特征值和查询=$1[L,QSA]
#重写规则^service/$content/index.php?content=service&query=$1[L,QSA]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
使用以下代码:-

RewriteEngine On
RewriteRule ^unternehmen-2-2/?$ /unternehmen [L,R=301,NC]

希望它能帮助您:)

虽然这不会“重定向url中带有
/unternehmen-2-2
的所有url”-但它只重定向与该url完全匹配的url。但是,如果这是可行的,那么您的第二个示例也应该是可行的-这可能表明存在缓存问题?@w3dk哦,我看您是对的。此规则不会重定向Url中带有/unternehmen-2-2`的所有Url。有没有一个规则可以重定向包含
/unternehman-2-2
的所有URL???试试这个规则:-重定向301/unternehman-2-2/unternehman或RewriteRule^(.*)unternehman-2-2(.*$$1internehman$2[R=301,L]好吧,理论上,你只需要删除
RewriteRule
模式上的尾部
/$
。然而,这与问题中所述的第二个示例“相同”(除了替换项上的尾随斜杠),这就引出了问题(根据我的评论)。。。为什么第一次没用?(顺便说一句,你千万不要把
重定向
(mod_别名)和
重写规则
(mod_rewrite)重定向混在一起,因为它们属于不同的模块,在不同的时间运行,所以很容易导致冲突。)谢谢你的回答!当我在RewriteRule^Unternehman-2-2/Unternehman[L,R=301,NC]上进行重写引擎时(在单独的行中),我得到一个500错误。。。