Understanding redirection - .htaccess

We are moving up from Joomla 1.5 to Joomla 3.0 and had a discontinued Podcast module.
I wrote my own version (it's tested and working), but now I need to redirect the old podcast URL to the new one.
I tried putting this line in the .htaccess, but it doesn't work. Why?
Redirect 301 http://oar2.org/index.php?option=com_podcast&view=feed&format=raw&Itemid=100 http://oar2.org/rss.php

Assuming that you've got the correct from URL and to URL in your Redirect statement (Redirect <from> <to>), then something important that you've missed is that you can't match against the query string using the Redirect directive (query string is everything starting with the ?). You need to use mod_rewrite's %{QUERY_STRING} variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^option=com_podcast&view=feed&format=raw&Itemid=100$
RewriteRule ^index.php$ /rss.php? [L,R=301]

Related

htaccess rewrite for known URL and query string

Have been struggling with a 301 redirect issue and cannot see the wood for the trees. Really hope someone can assist.
I have over 400 old urls that we need to redirect to a new urls. I have however modified the htaccess to create a clean url on the new site and am not sure if this is causing an issue or if I am doing something else wrong.
To clean urls in the new site I have added the following to the htaccess fle:
RewriteEngine On
RewriteRule ^([0-9]+) category?cat=$1 [NC,L,QSA]
This is so that instead of www.mysite/category?cat=1 I can have www.mysite/1 and-add-other-information
I am now trying to do the redirects for the 400 urls such as:
RewriteRule ^category?cat=1 1/and-add-other-information [R=301,NC,L,QSA]
RewriteRule ^category?cat=2 1/and-different-information [R=301,NC,L,QSA].
I know the L flag makes a difference and have tried this with and without.
I hope this makes sense.
QueryString isn't part of match in pattern of a RewriteRule.
You need to use RewriteCond directive and match against %{QUERY_STRING} variable like the following :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat=1$
RewriteRule ^category$ /and-add-other-information? [R=301,NC,L,QSA]

Redirect Joomla core pages via .htaccess

I'm having trouble redirecting Joomla's core pages via .htaccess; for instance, I need
/component/users/?view=login
to redirect to another page, but the server seems to ignore the redirect entirely. Is there something I'm missing here? Currently, I'm trying to use:
Redirect /component/users/?view=login http://www.example.com/
You can't match against the query string in a Redirect, you need to use the %{QUERY_STRING} variable and mod_rewrite. Above any other rules you may already have in the htaccess file in your document root, add:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)view=login(&|$)
RewriteRule ^component/users/$ http://www.example.com/? [L,R]

htacess url rewrites for .php?=n

I'm looking to rewrite old PHP pages to new locations, however the previous system used URLs structured as follows:
/old-page.php?page=Our%20Services
I've tried the following:
Redirect 301 /old-page.php?page=Our%20Services http://www.newdomain.co.uk/our-services/
Can someone help explain to me why the rewrite rule ignores everything after the question mark please?
You can use Redirect for simple cases only. If you want to check the query string, you must use mod_rewrite and RewriteCond
RewriteEngine on
RewriteCond %{QUERY_STRING} page=Our%20Services
RewriteRule ^old-page.php$ http://www.newdomain.co.uk/our-services/ [R,L]
This checks, if the query string contains page=Our%20Services and the URL path is old-page.php. It then redirects the client to the new URL http://www.newdomain.co.uk/our-services/.

Redirect joomla 1.5 RSS feeds to new onw via htaccess

I would like to redirect old joomla 1.5 RSS Feeds to new ones via htaccess. For example I have an old URL: http://www.mydomain.tld/en/categories/debian.feed?type=atom
and wish to redirect it to: http://www.mydomain.tld/en/?format=feed&type=rss
I tried it with the following htaccess rule, but it didnĀ“t work:
RewriteRule ^de/categories/([a-z]+)\.feed?type=atom$ http://www.mydomain.tld/en/?format=feed&type=rss [R=301,L]
RewriteRule ^en/categories/([a-z]+)\.feed?type=atom$ http://www.mydomain.tld/en/?format=feed&type=rss [R=301,L]
did anybody know whats wrong with my rule, or did have a working one for me?
I think the query string is your problem - you can't match on that with a rewrite rule. Try something like:
RewriteCond %{QUERY_STRING} ^type=atom$
RewriteRule ^de/categories/([a-z]+)\.feed$ http://www.mydomain.tld/en/?format=feed&type=rss [R=301,L]

Mod_Rewrite for htaccess

The URL structure for Joomla 1.5 changed in version 2.5.
Before it was:
http://example.com/index.php?option=com_content&task=view&id=587&Itemid=73
Now it's:
http://example.com/index.php?option=com_content&view=article&id=587&Itemid=114
*Note the id and itemid numbers change based on page and while all pages have an id not all have the Itemid in the url.
While we updated all links in the database lots of people still have the old link structure so we want to edit the htaccess file so if someone enters the old structure it will forward to the right structure.
Simply put any URL entered at example.com with task=view in the url should be replaced with view=article.
Does anyone know a simply way to do this in htaccess, maybe with replace query string method and 301 redirect?
You can match against the query string using mod_rewrite's RewriteCond and the %{QUERY_STRING} variable. Then use the % backreferences in a RewriteRule
Try something like this:
RewriteCond %{QUERY_STRING} ^(.*)&task=view&(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1&view=article&%2 [R=301,L]

Resources