Regex htaccess是';t按预期重定向
我的htaccess文件有问题 通常我会把喜欢的Regex htaccess是';t按预期重定向,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我的htaccess文件有问题 通常我会把喜欢的 RewriteEngine On Redirect 301 /path/and/more/stuff/filename.doc http://www.domain.tld/ 进入htaccess,它会将打开我的域上不再存在的路径的用户重定向到主域 我也试过了 RewriteEngine On Redirect 301 /path/and/more/stuff/filename.doc http://www.domain.tld/? 但结果是一
RewriteEngine On
Redirect 301 /path/and/more/stuff/filename.doc http://www.domain.tld/
进入htaccess,它会将打开我的域上不再存在的路径的用户重定向到主域
我也试过了
RewriteEngine On
Redirect 301 /path/and/more/stuff/filename.doc http://www.domain.tld/?
但结果是一样的
但出于某种原因,我的htaccess完全忽略了我。Wordpress正常工作。我现在已经在htaccess的顶部添加了代码,但它仍然将我重定向到Wordpress的404错误页面
我错过了什么
我用于测试的代理服务器显示了相同的结果(之前在htaccess中也有一些缓存行,但现在它们都被删除了)
完整的htaccess如下所示:
RewriteEngine On
Redirect 301 /path/and/more/stuff/filename.doc http://www.domain.tld/?
Redirect 301 /path/filename.pdf http://www.domain.tld/?
Redirect 301 /path/and/filename.xls http://www.domain.tld/?
Redirect 301 /path/and/more http://www.domain.tld/?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
重新编写引擎打开
重定向301/path/和/more/stuff/filename.dochttp://www.domain.tld/?
重定向301/path/filename.pdfhttp://www.domain.tld/?
重定向301/path/和/filename.xlshttp://www.domain.tld/?
重定向301/路径/和/或更多http://www.domain.tld/?
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
我相信我这样做是正确的,我的其他博客也能很好地使用这种重定向不要将
mod_rewrite
规则与redirect
指令混合使用。试试这些规则:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^path/(and/more/stuff|filename\.pdf) http://www.domain.tld/? [L,NC,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写规则^path/(和/more/stuff | filename\.pdf)http://www.domain.tld/? [L,NC,R=302]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
太好了,我现在可以重新定向文件了。只有一个重定向不起作用:。。因为它只是一个文件夹?添加了重写规则^vb/http://www.domain.tld/? [L,NC,R=302]
但这似乎不是正确的方法:(/vb/
文件夹是否有单独的.htaccess?否则重写规则^vb/?http://www.domain.tld/? [L,NC,R=302]
应该在RewriteBase
line.DOH下面工作。我甚至没有想过只创建文件夹并添加一个htaccess,将所有内容重定向回站点。这将解决刚刚出现的大量编写工作(找到了200多个需要重定向的文件。非常感谢您的提醒..应该会产生奇迹;)