in .htaccess I would like to chop off anything after the 2nd '/'… so http://www.domain.com/parent/child/otherchild would be redirected to http://www.domain.com/parent/
问问题
104 次
2 回答
0
启用mod_rewrite
并.htaccess
通过httpd.conf
然后将此代码放入您的DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteRule ^([^/]+/).+$ /$1 [L,R=301]
于 2013-10-23T21:35:07.563 回答
0
将这些规则添加到文档根目录中的 htaccess 文件中:
RewriteEngine On
RewriteRule ^([^/]+)/.+$ /$1/ [L,R=301]
不确定在评论中粘贴所有不可读的代码是什么意思,但您想添加我在评论中提到的排除条件:
AddType application/octet-stream vcf
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|js)$ [NC]
RewriteRule ^([^/]+)/.+$ /$1/ [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/wp-content/themes/myTheme/style.css
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
此行是一个排除项,因为!
:
RewriteCond %{REQUEST_URI} !\.(css|js)$ [NC]
这意味着如果URI 以.css
或不应用该规则结尾。您可以根据需要添加其他人。假设您不想重定向 URI 之类的 : ,然后还添加:.js
/foo/bar/no-redirect/
RewriteCond %{REQUEST_URI} !^/foo/bar/no-redirect/
于 2013-10-23T21:35:13.853 回答