我有几个网址我想从网址中删除整个directoy部分。 htaccess 301重定向会是什么?有人可以帮忙。
例如
https://example.com/first-lastname-word1-word2/biography/firstnamelastname
https://example.com/first-lastname-word1-word2/activity/firstnamelastname
https://example.com/first-lastname-word1-word2/announcements/firstnamelastname
https://example.com/first-lastname-word1-word2/wall/firstnamelastname
成为https://example.com/activity/firstnamelastname https://example.com/biography/firstnamelastname等等。
答案 0 :(得分:2)
使用mod_rewrite
将此规则非常优先的第一条规则放在RewriteEngine
行的下方:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(memorial-photos|videos|images|category)/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+/([^/]+/[^.]+)$ /$1 [L,NE,R=301]