I develop a new drupal website to replace another website. So, in order to not loose my Google SEO from the old website, I create URL rewriting rules.

Everything is ok except for old urls beginning with index.php, like index.php?title=plip

I would like to redirect like this :

RedirectPermanent /index?title=plip http://new.drupal/my-page

It is normal because of this, in Drupal .htaccess file :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

But how can I do to get my redirection from urls like index.php?title=plip ?

I tried with the flag S to create an If-Else-like rule but it doesn't work.

Is there any chance to make it possible ?

  • Any feedback about my answer? – Pierre.Vriens Jun 7 '16 at 6:39
  • I finaly found a solution. The syntax is the following : ``` RewriteCond %{REQUEST_URI} /index.php$ RewriteCond %{QUERY_STRING} ^title=plip RewriteRule ^(.*)$ new.drupal/my-page? [L,R=301] ``` – lazzio Aug 1 '16 at 14:30

You should be able to make this work using the Rules module, as detailed below.

Looking at your path (= /index.php?title=plip) I would try to make the value (= plip) of the URL argument (= title) available as a new variable to the Rules module. To do so, you can use the Rules URL Argument module. Here is a quote about it (from its project page):

... provides two rules conditions based on URL arguments:

  • check if a URL argument is present.
  • compare the value of an URL argument.

It also provides an action that makes the value of an URL argument available as new variable to Rules.

The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.

For an example of how to use it, refer to Comment # 3 in issue # 1686360 which is about "Pass an amount to the url, ie; site/content/node-title?amount=10 or /node-title?=amount:10". Here is the relevant part of it:

  • add a "Check if URL argument exist" condition to your rule and set the "ARGUMENT" value to "amount".
  • add "Provide URL argument value" action to the rule and set "URL ARGUMENT NAME" value to "amount" and in the "Provided variables" section "ARGUMENT FROM URL - Variable name" to e.g. "amount_from_url".

You will now be able to use the amount value as a variable "amount-from-url" for other actions in this rule.

|improve this answer|||||
  • 1
    I will try to do this in a project, thanks for the answer – Adrian Cid Almaguer Dec 18 '15 at 5:33
  • I'd be interested in knowing WHY this answer was downvoted ... Because I think it is a perfect example of how Rules can often help you to get around this kind of .htaccess limitations (stmr-sltl=c) – Pierre.Vriens Dec 18 '15 at 6:05
  • 1
    I am SURE it's not yours (don't worry about that). But IF the downvote would be because the answer is not 100% clear THEN that would be a perfect reason to downvote it ... provided a comment related to it was added like "I don't understand, please improve your answer" ... THAT should be a motivation (incentive) to enhance the answer until the downvoter gets it, and hopefully result in an un-downvote ... Or to put it in another ways (a): NOT talking about a problem will NOT solve it. ... (b) GOOD teachers correct/challenge their students where needed, so that they can learn from mistakes. – Pierre.Vriens Dec 18 '15 at 6:22
  • 1
    I fully agree with the option b), because I am a professor at a university ;-) – Adrian Cid Almaguer Dec 18 '15 at 6:26
  • 1
    At this moment I teach "Database Systems (Postgres)" and "Web Application Development with Drupal" ;-). Off course I talk to my students about SE-family of sites, I have some of they in stackoverflow. I agree with option a) too – Adrian Cid Almaguer Dec 18 '15 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.