如何在htaccess上重定向html文件


How to make a redirection of html files on the htaccess?

我有以下URL:

http://superawesomedomain.com/recently-created.html
http://superawesomedomain.com/recently-created.html
http://superawesomedomain.com/articles/recently-created.html
http://superawesomedomain.com/surveys/0-6-months.html

我想将它们重定向到以下URL:

http://superawesomedomain.com/search_redirect?q=recently-created
http://superawesomedomain.com/search_redirect?q=recently-created
http://superawesomedomain.com/search_redirect?q=recently-created
http://superawesomedomain.com/search_redirect?q=0-6-months

我在获取文件名(没有扩展名)并将其附加到我想要的url时遇到了问题。

我必须用.htaccess 进行重定向

我将非常感谢你的帮助。

这不管用吗?

/recently-created.html /search_redirect?q=recently-created
/recently-created.html /search_redirect?q=recently-created
/articles/recently-created.html /search_redirect?q=recently-created
/surveys/0-6-months.html /search_redirect?q=0-6-months

您只需要使用http://superawesomedomain.com如果在另一台服务器上。

您可以在/root/.htaccess:中使用以下重定向

RedirectMatch 302 ^/(?:[^/.]*/)?([^.]+)'.html$ http://domain.com/search_redirect/?q=$1

这将重定向

/foo/bar.html

/bar.html

/search_redirect/?q=bar

如果要使重定向永久化,请将状态代码302更改为301

参考:-https://httpd.apache.org/docs/current/mod/mod_alias.html