1

I have several urls on a Joomla site which have been indexed and I need to 301 redirect them into some new pages. The old URL is formed like this:

http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=20

I want it to go to:

http://www.mydomain.com/en/family-members/family-disease

I tried using:

RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^/en/wfmenuconfig/family/family-disease/177-category-english$ http://www.www.mydoamin.com/en/family-members/family-disease%1 [R=301,L]

I've tried several answers on here but nothing seems to be working.

htaccess 301 redirect dynamic url

and

301 Redirecting URLs based on GET variables in .htaccess

Any ideas what I should try next? (I've tried a normal redirect 301)

Community
  • 1
  • 1
  • Post your best guess at a solution as a starting point. – isherwood Apr 08 '13 at 16:06
  • I tried using: `RewriteCond %{QUERY_STRING} ^start=(.*)$ RewriteRule ^/en/wfmenuconfig/family/family-disease/177-category-english$ http://www.www.mydoamin.com/en/family-members/family-disease%1 [R=301,L]` – Andrew Matthews Apr 08 '13 at 16:08
  • Check out this: [Adapting Custom URLs with .htaccess or tool](http://stackoverflow.com/questions/15634494/joomla-2-5-adapting-custom-urls-with-htaccess-or-tool/15654818#15654818). More convenient than messing with .htaccess – piotr_cz Apr 09 '13 at 08:06
  • Thanks for the replies, I tried using the tool in joomla and that has not worked to forward the user to the desired url. – Andrew Matthews Apr 09 '13 at 11:39

4 Answers4

0

You've almost got it. You need to remove the leading slash from your rule's pattern because it's removed from the URI when applying rules from an htaccess file:

RewriteCond %{QUERY_STRING} ^start=(.*)$ 
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease%1? [R=301,L]

You also don't need the http://www.www.mydoamin.com bit (2 sets of www). At the end of your target, you have family-disease%1, which means if start=20 then the end of your URL will look like: family-disease20. Is that right?

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

The new URL doesn't have the query string in it, so it is just stripping of the last URL path part. If you want it hardcoded

RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease? [R,L]

or a little bit more flexible

RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/.+$ /en/family-members/family-disease? [R,L]

or if you just want to keep two levels after en/wfmenuconfig

RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/(.+?/.+?)/ /en/$1? [R,L]

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

If you just want to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease, then you must try these directives:

# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease [R=301,L]

But if that's not what you want, but to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease$var then you could check this one:

# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease%1 [R=301,L]

Now, give this one a little more try if it will work. If it's not, then find any suspicious why this code is not working:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /en/

RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^wfmenuconfig/family/family-disease/177-category-english /family-members/family-disease [R]

And go to http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$AnyNumber if it's redirecting into http://www.mydomain.com/en/family-members/family-disease just make sure that your web server have mod_rewrite.

0

I just wanted to throw this out there, I was also having trouble getting the RewriteRule to work. I have a client that upgraded to a WordPress powered site from .asp pages. What I had to do to get this to work is insert the RewriteCond and RewriteRule in the htaccess file BEFORE the "# BEGIN WordPress" section. Now it works just as it should.

This is posted way late, but hopefully it helps someone else out there running into the same issue.

Doesn't Work:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]

Does Work:

RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Order of operations must be important =)