htaccess 重写而不重定向 [英] htaccess rewrite without redirect
问题描述
我想要做的就是将网址从 www.exaple.hu 重写为 www.exaple.cz/hu.所以在地址 www.exaple.cz/hu 下显示了来自地址 www.exaple.hu 的内容.
All i want to do is to rewrite url from www.exaple.hu to www.exaple.cz/hu. So under address www.exaple.cz/hu is displayed content from adress www.exaple.hu.
因此,当用户输入 www.exaple.cz/hu 时,用户不会被重定向到 www.exaple.hu,但来自 www.exaple.hu 的内容显示在域 www.exaple.cz/下hu(所以在地址栏中是 www.exaple.cz/hu).
So when user type www.exaple.cz/hu, user is not redirected to www.exaple.hu but content from www.exaple.hu is displayed under domain www.exaple.cz/hu (so in adress bar is www.exaple.cz/hu).
推荐答案
为此,您需要在 Apache 配置中启用 mod_proxy.启用 mod_proxy 后,通过 httpd.conf
启用 mod_rewrite 和 .htaccess,然后将此代码放在 DOCUMENT_ROOT
目录下的 .htaccess
中:>
You will need to enable mod_proxy in your Apache config for that. Once mod_proxy is enabled, enable mod_rewrite and .htaccess through httpd.conf
and then put this code in your .htaccess
under DOCUMENT_ROOT
directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.exaple\.cz$ [NC]
RewriteRule ^(hu)/?$ http://www.exaple.$1 [L,P,NC]
这篇关于htaccess 重写而不重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!