apache - .htaccess 重定向 更改 URL

标签 apache .htaccess mod-rewrite web

我希望将 example.com/foo/[some string]FOOBAR 重定向到 subdomain.example.com/[some string]Foobar

我在我的 .htaccess 文件中使用 RedirectMatch 301/foo/(^.*$)FOOBAR http://subdomain.example.com/$1Foobar 这不起作用,只会导致 404

有什么建议吗?

最佳答案

这很可能是因为您有以下规则:

RedirectMatch 301 /foo/(^.*$)FOOBAR http://subdomain.example.com/$1Foobar

其中,您已将 $ 放在括号内!尝试以下方法:

RedirectMatch 301 /foo/(^.*)FOOBAR$ http://subdomain.example.com/$1Foobar

关于apache - .htaccess 重定向 更改 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10163391/

相关文章:

.htaccess - 如何使用 htaccess 中的重定向从 URL 中删除 index.php(主页)和 php(其他页面)

.htaccess - Mod_rewrite 不适用于以 %(百分号)开头的 url

apache - .htaccess 重写规则 : what is the differences between %1 and $1 variables (percentage vs dollar sign)?

apache - 如何配置 mod_deflate 以提供使用 Assets :precompile 准备的压缩 Assets

linux - Apache 测试页 : how do I get it to come up?

.htaccess - 301 将所有没有扩展名的文件重定向到 .html 扩展名

javascript - 创建 AJAX 导航的最佳实践是什么?

regex - 重定向 .htaccess - 删除 url 的最后一部分

apache - 在提供页面后,HTTP 套接字连接仍处于 TIME_WAIT 状态

php - 使用 `.htaccess` RewriteEngine 规则在 php 中获取值