在.htaccess条件重写规则重写、规则、条件、htaccess

2023-09-02 11:27:43 作者:灵魂深处゛只有你

我有一个DNS,我有3项,如下

I have a DNS where I have 3 entries as below

    www A 1.1.1.1
    blog A 1.1.1.1
    post A 1.1.1.1

现在我的主要网站www.something.com这是工作的罚款

Now My main website is www.something.com which is working fine

现在我想blog.something.com应该重定向到www.something.com/?page_id=2461

now i want blog.something.com should redirect to www.something.com/?page_id=2461

&放大器;

post.soemthing.com应该重定向到www.something.com/?page_id=2409

post.soemthing.com should redirect to www.something.com/?page_id=2409

DNS和Web服务器是在同一台物理机器。

DNS and Webserver is on same physical machine.

我是小新的.htaccess codeS。

I am little new to .htaccess codes.

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT 目录下:

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} ^blog.something.com$ [NC]
RewriteRule ^$ http://www.something.com/?page_id=2461 [R=302,L,QSA]

RewriteCond %{HTTP_HOST} ^post.something.com$ [NC]
RewriteRule ^$ http://www.something.com/?page_id=2409 [R=302,L,QSA]

一旦你验证它是否工作正常,更换 R = 302 R = 301 。避免使用 R = 301 (永久重定向),而测试你的mod_rewrite规则。

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.