Domanda

I have another redirect question. I am trying to add a condition to a few redirects (I have 50+ in the same file). the redirects that work are just domain conditional, meaning if the %{HTTP_HOST} matches then it goes. Now i am trying something with a few of them that does that but also needs to only redirect a specific folder only. This is what I have:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/some/page.php
RewriteCond %{HTTP_HOST} (^|\.) domain\.com$
RewriteRule ^ https://www.example.com/some/new/page/ [R=301,L]

Simply put I am trying to match a specific domain and URI and forward that to a new domain and page. ex: domain.com/account/blah.php

redirect to www.example.com/some/new/page/

and at the same time I have another redirect for the domain if no URI they are both specified like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.) domain\.com$
RewriteRule ^ https://www.example.com/some/other/new/page/ [R=301,L]
RewriteCond %{REQUEST_URI} ^/some/page.php
RewriteCond %{HTTP_HOST} (^|\.) domain\.com$
RewriteRule ^ https://www.example.com/some/new/page/ [R=301,L]

Any idea what i am doing wrong?

È stato utile?

Soluzione

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Check domain matched but uri doesn't
    RewriteCond %{HTTP_HOST} (^|\.) domain\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/some/page.php [NC]
    RewriteRule ^ https://www.example.com/some/new/page/ [R=301,L]

    # Check domain matches and uri matches
    RewriteCond %{HTTP_HOST} (^|\.) domain\.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/some/otherpage.php [NC]
    RewriteRule ^ https://www.example.com/some/other/new/page/ [R=301,L]
</IfModule>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top