2个简单的.htaccess url-rewrite规则

时间:2014-11-16 16:21:17

标签: .htaccess mod-rewrite url-rewriting rewrite

我正在尝试设置2条规则:

  1. 如果我输入http://www.mydomain.it/notizie/LeDelizieDiCasa,则htaccess必须加载http://www.mydomain.it/?rssfeed=LeDelizieDiCasa
  2. www.mydomain.it/categoria/Cucina htaccess必须加载http://www.mydomain.it/?categoryfeed=Cucina
  3. 我试过了:

    RewriteCond %{REQUEST_URI} ^/?rssfeed=Cucina
    RewriteCond %{HTTP_HOST} ^(www.)?mydomain.it$ [NC]
    RewriteRule ^(.*)$ http://www.mydomain.it/categoria/Cucina [R,L]
    

    但它不起作用,如果我转到http://www.mydomain.it/categoria/Cucina,我会返回错误404.

    谁能帮帮我?

    mycurrent .htaccess:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    #rule 1
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.it$ [NC]
    RewriteRule ^notizie/([^/]+)$ /?rssfeed=$1 [L]
    
    #rule 2
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.it$ [NC]
    RewriteRule ^categoria/([^/]+)$ /?categoryfeed=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    

    非常感谢

1 个答案:

答案 0 :(得分:0)

很难帮助你,因为我没有看到你的问题或你的问题...... 我不知道你为什么要添加www.

1)使用以下内容将notizie/LeDelizieDiCasa重定向到http://www.mydomain.it/?rssfeed=LeDelizieDiCasa

RewriteRule notizie/LeDelizieDiCasa/? http://www.mydomain.it/?rssfeed=LeDelizieDiCasa [NC,L]

2)将/categoria/Cucina重定向到http://mydomain.it/?categoryfeed=Cucina

RewriteRule categoria/Cucina/? http://www.mydomain.it/?rssfeed=LeDelizieDiCasa [NC,L]

#rule 1之前添加。

问问,如果不是......