1

I've got a problem with redirecting some page(s). My rewrite rule looks like that (example):

RewriteRule /index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position$ article-keyword.html [R=301,L]

But it's not working, i was trying some different combinations but it still doing nothing. Any solution?

j0k
  • 22,600
  • 28
  • 79
  • 90
Kamil
  • 782
  • 1
  • 6
  • 22
  • Can you add some documentation on what you are specifically trying to accomplish? From the rule you have posted, you appear to want to change a very specific URL `/index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position$` to `article-keyword.html` If that is the case, is this redirection not taking place? – HeatfanJohn Jul 09 '12 at 15:16
  • yeah I have several specific links which I would like to redirect – Kamil Jul 09 '12 at 15:27

1 Answers1

0

Update: The RewriteRule below is incorrect. See update for 7/9/2012 for more details

I have read that RewriteRules are always relative, therefore try:

RewriteRule ^index\.php\?option=com_content&view=article&id=47:article-keyword&catid=8:position$ article-keyword.html [R=301,L]`

This should redirect /index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position to article-keyword.html

The ^ designates the beginning of the string. Please take a look at http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html for more information on Apache's RewriteRule.

Update - 2012-07-08

Ok, after reading the Apache documentation, the RewriteRule DOES NOT match on the query string. To match on data within the query string you need to use a RewriteCond and the %QUERY_STRING variable.

Success! The following worked for me!

RewriteCond %{QUERY_STRING} option=com_content&view=article&id=47:article-keyword&catid=8:position
RewriteRule ^index\.php$ article-keyword.html? [R=301,L]

This redirected http://site.domain.com/index.php?option=com_content&view=article&id=47:article-keyword&catid=8:position to http://site.domain.com/article-keyword.html

This only redirects requests to index.php that have the query string in question.

HeatfanJohn
  • 7,143
  • 2
  • 35
  • 41
  • Thanks for reply, but still not redirecting, I've already tried that ^ at beginning, nothing helped. – Kamil Jul 09 '12 at 15:30
  • Where are you placing this RewriteRule? If in .htaccess, please post the entire .htaccess file. – HeatfanJohn Jul 09 '12 at 15:30
  • I'm placing that right after RewriteEngine On statement and RewriteBase (also tried without setting RewriteBase). – Kamil Jul 09 '12 at 15:33
  • I think the issue is that your literal string contains regex special characters that require escaping. See this [SO](http://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions) article on that. These characters `.^$*+?()[{\ ` require escaping. I am going to update my posting to include the requires escaping ('\'). Upon further review, the `?` definitely requires escaping `\?`. – HeatfanJohn Jul 09 '12 at 15:52
  • Please post your .htaccess file so we can troubleshoot in more detail. Perhaps something else in the file is interfering with the desired redirect. – HeatfanJohn Jul 09 '12 at 17:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13626/discussion-between-kamil-and-heatfanjohn) – Kamil Jul 09 '12 at 17:09
  • Actually, this isn't working for me either. Let me play with it for a few minutes and I'll update you on what I find. – HeatfanJohn Jul 09 '12 at 17:18
  • I finally got it to work. I have updated my answer with what worked for me. – HeatfanJohn Jul 09 '12 at 18:23