RewriteCond htaccess problem


#1

Okay, so I have an old page that uses a system with variable in the URL query, and I want to update that page to a new version where I have changed this information.

What I have on the old page are URLs like this: website.com/index.php?lang=en&act=art
or
website.com/index.php?act=con&lang=fr

(notice that act= and lang= may be on different spots in the query).

What I need is to redirect people getting to those URLs to the new query names.

What the new system looks like:
website.com/index.php?language=english&page=articles
or
website.com/index.php?language=french&page=contact

(notice that I need language= to be first all the time now).

This should be possible with a simple expression I belive.

#RewriteCond %{QUERY_STRING} act=(.)
#RewriteRule ^index.php(.
) /index.php?page=%1 [R]
Something like this? But it’s not working out for me.

If it’s not possible or good to do it by rules, I have a list of exact URLs that I want replaced, and I’ll gladly do it manually as long as the query-strings (anything after? will be recognized and I can control it).

So what I would also do is a manual list of:
website.com/index.php?act=pre&lang=fr
to
website.com/index.php?language=francais&page=articles

The system I currently have in place is like this to fix URLs:
#4 strings = sorted categories for articles etc.
RewriteRule ^public_html/subdir/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /subdir/index.php?language=$1&page=$2&sort=$3&id=$4
#3 strings = specific articles
RewriteRule ^public_html/subdir/([^/]+)/([^/]+)/([^/]+)/$ /subdir/index.php?language=$1&page=$2&read=$3
#2 strings = language specific pages
RewriteRule ^public_html/subdir/([^/]+)/([^/]+)/$ /subdir/index.php?language=$1&page=$2
#1 string = any page in english
RewriteRule ^public_html/subdir/([^/]+)/$ /subdir/index.php?language=english&page=$1

Anyone have any suggestions on how to fix this?

Thanks in advance,
MNeMiC


#2

I’ve got some tips about how to work with the condition and to rewrite it, but it still doesn’t work. Is there something wrong with my syntax here?

RewriteCond %{QUERY_STRING} (^|&)act=pre(&|$)
RewriteRule ^index.php$ /english/press/

If I have that and I enter:
http://www.website.org.uk/subdir/index.php?act=pre

Where would that take me?


#3

So to sum this problem that is now solved up for future searchers as I had such a problem with it where most of the code that I found while searching didn’t work for me.

The solution to redirect from old PHP query to a new PHP query with the same page was as follows:

######################################

# #Convert old URLs to new URLs# #

#When the user has entered both the language and the page#

RewriteCond %{QUERY_STRING}>english ^([^&]&)lang=en(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>francais ^([^&]&)lang=fr(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>deutch ^([^&]&)lang=de(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>espanol ^([^&]&)lang=es(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>italiano ^([^&]&)lang=it(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>svenska ^([^&]&)lang=sv(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>norsk ^([^&]&)lang=no(&[^&>])>(.+)$
RewriteRule ^index.php$ - [E=qLang:%3,C]

RewriteCond %{QUERY_STRING}>press ^([^&]&)act=pre(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>articles ^([^&]&)act=art(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>faq ^([^&]&)act=faq(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>help ^([^&]&)act=hlp(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>contact ^([^&]&)act=con(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>error ^([^&]&)act=err(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>emg ^([^&]&)act=emg(&[^&>])>(.+)$
RewriteRule ^index.php$ http://www.website.org.uk/%{ENV:qLang}/%3/? [R=301,L]

#When the user has entered both the language and the page#

#When the user has entered only the page#

RewriteCond %{QUERY_STRING}>press ^([^&]&)act=pre(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>articles ^([^&]&)act=art(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>faq ^([^&]&)act=faq(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>help ^([^&]&)act=hlp(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>contact ^([^&]&)act=con(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>error ^([^&]&)act=err(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>emg ^([^&]&)act=emg(&[^&>])>(.+)$
RewriteRule ^index.php$ http://www.website.org.uk/%3/? [R=301,L]

#When the user has entered only the page#

#When the user has entered only the language#

RewriteCond %{QUERY_STRING}>english ^([^&]&)lang=en(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>francais ^([^&]&)lang=fr(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>deutch ^([^&]&)lang=de(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>espanol ^([^&]&)lang=es(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>italiano ^([^&]&)lang=it(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>svenska ^([^&]&)lang=sv(&[^&>])>(.+)$ [OR]
RewriteCond %{QUERY_STRING}>norsk ^([^&]&)lang=no(&[^&>])>(.+)$
RewriteRule ^index.php$ http://www.website.org.uk/%3/home/? [R=301,L]

#When the user has entered only the language#

# #Convert old URLs to new URLs# #

######################################

#########################################

# #Redirect http:// to http://www.# #

RewriteCond %{HTTP_HOST} ^website.org.uk$
RewriteRule (.*) http://www.website.org.uk/$1 [R=301,L]

# #Redirect http:// to http://www.# #

#########################################

##############################

# #Add trailing slashes# #

RewriteRule ^/(.+/)?([^.][^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

# #Add trailing slashes# #

##############################