Samuel Ramzan
Samuel Ramzan

Reputation: 1856

htaccess redirect incomplete task

A couple of days ago I asked a question that could not be answer an I almost have it but not quite, I'm sure that it’s something I'm missing and you guys can help me...

Here is the code:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^monitorbc\.info$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.monitorbc\.info$
    RewriteRule ^notas\.php?(.*) "https://monitorbc.info/monitor3/notas.php?" [R=301,L]

    # one of the links from the old site = https://monitorbc.info/notas.php?id=699&sec=economia
    # It should end up like this = https://monitorbc.info/monitor3/notas.php?id=699&sec=economia

The problem is that it does redirect but for some reason the redirect stops at the ? sign so it’s not completing the task.

Hope I’m making sense this time.

Upvotes: 1

Views: 54

Answers (1)

Jon Lin
Jon Lin

Reputation: 143886

You can't match against the query string in a rewrite rule, you can only match against the %{QUERY_STRING} variable inside a rewrite condition. The ? you have in your expression gets evaluated as the last "p" in "php" is optional. But since you don't seem to be using the query string anyways. Remove all the ? marks. By default the query string is appended to the target of your rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^monitorbc\.info$ [OR]
RewriteCond %{HTTP_HOST} ^www\.monitorbc\.info$
RewriteRule ^notas\.php$ https://monitorbc.info/monitor3/notas.php [R=301,L]

Upvotes: 1

Related Questions