Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond problem with .htaccess

STRING_QUERY from old to new variable names

         

MNeMiC

5:40 pm on Apr 15, 2010 (gmt 0)

10+ Year Member



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:
http://www.website.com/index.php?lang=en&act=art

or
http://www.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:
http://www.website.com/index.php?language=english&page=articles

or
http://www.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:
http://www.website.com/index.php?act=pre&lang=fr

to
http://www.website.com/index.php?language=francais&page=articles


Anyone have any suggestions on how to fix this?

Thanks,
Henrik

g1smd

6:20 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To start, you'll need to make a list of all the mappings you're interested in.

It's certainly possible, and it's also possible with the parameters in any order.

Several things are worth mentioning if you are changing URLs on your site.

You're quite correct to redirect old requests to the new URL. The redirect needs to state the new domain name and use the [R=301,L] flags.

The new URL could be simplified. There's no need whatsoever for '
index.php
' to appear in the URL. In particular,
/index.php?language=francais&page=articles
is implementation detail that does not need to be exposed to users. I'd look at using extensionless URLs with a format like
example.com/francais/articles
feeding a rewrite to fetch the content from the script.

There are clear benefits in using a structured URL format such as that.

MNeMiC

7:39 pm on Apr 15, 2010 (gmt 0)

10+ Year Member



Thanks for the quick reply.

I'll start off by adding that I've currently created a couple of RewriteRules for the page to convert the "new index.php" to better URLs.

So right now the visitors will be linked around the page like this:
www.website.com/language/page/
And on some pages I use more information so I have 3 or 4 vairables like:
www.website.com/language/articles/category/categoryName/
or
www.website.com/language/press/my-press-release-name/

These are however just simplified versions of:
www.website.com/index.php?language=english&page=articles&sort=category&id=categoryName

Which I have created the following htaccess for:

#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

Note that the "subdir" is just for testing purposes, I will remove it once I overwrite the old version of the page.

I know that I'll need to make sure that the old URLs new name will match the new structure, though I don't know if I should mask them to the index.php?query version or the /neat/structured/new/version/


I do have a full list of URLs that I'll need to remap, it's about 110 units long so I figured I wouldn't mess up the topic with them.

There aren't really anything special in them but here are a few different ones that were found when I generated a sitemap to the old page:

http://www.website.org.uk/index.php?act=&lang=en

http://www.website.org.uk/index.php?act=&lang=fr

http://www.website.org.uk/index.php?act=&lang=de

http://www.website.org.uk/index.php?act=&lang=es

http://www.website.org.uk/index.php?act=&lang=it

http://www.website.org.uk/index.php?act=&lang=sv

http://www.website.org.uk/index.php?act=&lang=no

http://www.website.org.uk/index.php?lang=en

http://www.website.org.uk/index.php?act=pre&lang=en

http://www.website.org.uk/index.php?act=art&lang=en

http://www.website.org.uk/index.php?act=faq&lang=en

http://www.website.org.uk/index.php?act=hlp&lang=en

http://www.website.org.uk/index.php?act=con&lang=en

http://www.website.org.uk/index.php?ref=&lang=en

http://www.website.org.uk/index.php?ref=&lang=en&act=pre

http://www.website.org.uk/index.php?ref=&lang=en&act=art

http://www.website.org.uk/index.php?ref=&lang=en&act=faq

http://www.website.org.uk/index.php?ref=&lang=en&act=hlp

http://www.website.org.uk/index.php?ref=&lang=en&act=con

http://www.website.org.uk/index.php?ref=&lang=en&act=err

http://www.website.org.uk/content/empty.php

http://www.website.org.uk/index.php?lang=fr

http://www.website.org.uk/index.php?act=pre&lang=fr

http://www.website.org.uk/index.php?act=art&lang=fr

http://www.website.org.uk/index.php?act=faq&lang=fr

http://www.website.org.uk/index.php?act=hlp&lang=fr

http://www.website.org.uk/index.php?act=con&lang=fr

http://www.website.org.uk/index.php?ref=&lang=fr

http://www.website.org.uk/index.php?ref=&lang=fr&act=pre

http://www.website.org.uk/index.php?ref=&lang=fr&act=art

http://www.website.org.uk/index.php?ref=&lang=fr&act=faq

http://www.website.org.uk/index.php?ref=&lang=fr&act=hlp

http://www.website.org.uk/index.php?ref=&lang=fr&act=con

http://www.website.org.uk/index.php?ref=&lang=fr&act=err

http://www.website.org.uk/index.php?lang=de

http://www.website.org.uk/index.php?act=pre&lang=de

http://www.website.org.uk/index.php?act=art&lang=de

http://www.website.org.uk/index.php?act=faq&lang=de

http://www.website.org.uk/index.php?act=hlp&lang=de

http://www.website.org.uk/index.php?act=con&lang=de

http://www.website.org.uk/index.php?ref=&lang=de

http://www.website.org.uk/index.php?ref=&lang=de&act=pre

http://www.website.org.uk/index.php?ref=&lang=de&act=art

http://www.website.org.uk/index.php?ref=&lang=de&act=faq

http://www.website.org.uk/index.php?ref=&lang=de&act=hlp

http://www.website.org.uk/index.php?ref=&lang=de&act=con

http://www.website.org.uk/index.php?ref=&lang=de&act=err

http://www.website.org.uk/index.php?lang=es

http://www.website.org.uk/index.php?act=pre&lang=es

http://www.website.org.uk/index.php?act=art&lang=es

http://www.website.org.uk/index.php?act=faq&lang=es

http://www.website.org.uk/index.php?act=hlp&lang=es

http://www.website.org.uk/index.php?act=con&lang=es

http://www.website.org.uk/index.php?ref=&lang=es

http://www.website.org.uk/index.php?ref=&lang=es&act=pre

http://www.website.org.uk/index.php?ref=&lang=es&act=art

http://www.website.org.uk/index.php?ref=&lang=es&act=faq

http://www.website.org.uk/index.php?ref=&lang=es&act=hlp

http://www.website.org.uk/index.php?ref=&lang=es&act=con

http://www.website.org.uk/index.php?ref=&lang=es&act=err

http://www.website.org.uk/index.php?lang=it

http://www.website.org.uk/index.php?act=pre&lang=it

http://www.website.org.uk/index.php?act=art&lang=it

http://www.website.org.uk/index.php?act=faq&lang=it

http://www.website.org.uk/index.php?act=hlp&lang=it

http://www.website.org.uk/index.php?act=con&lang=it

http://www.website.org.uk/index.php?ref=&lang=it

http://www.website.org.uk/index.php?ref=&lang=it&act=pre

http://www.website.org.uk/index.php?ref=&lang=it&act=art

http://www.website.org.uk/index.php?ref=&lang=it&act=faq

http://www.website.org.uk/index.php?ref=&lang=it&act=hlp

http://www.website.org.uk/index.php?ref=&lang=it&act=con

http://www.website.org.uk/index.php?ref=&lang=it&act=err

http://www.website.org.uk/index.php?lang=sv

http://www.website.org.uk/index.php?act=pre&lang=sv

http://www.website.org.uk/index.php?act=art&lang=sv

http://www.website.org.uk/index.php?act=faq&lang=sv

http://www.website.org.uk/index.php?act=hlp&lang=sv

http://www.website.org.uk/index.php?act=con&lang=sv

http://www.website.org.uk/index.php?ref=&lang=sv

http://www.website.org.uk/index.php?ref=&lang=sv&act=pre

http://www.website.org.uk/index.php?ref=&lang=sv&act=art

http://www.website.org.uk/index.php?ref=&lang=sv&act=faq

http://www.website.org.uk/index.php?ref=&lang=sv&act=hlp

http://www.website.org.uk/index.php?ref=&lang=sv&act=con

http://www.website.org.uk/index.php?ref=&lang=sv&act=err

http://www.website.org.uk/index.php?lang=no

http://www.website.org.uk/index.php?act=pre&lang=no

http://www.website.org.uk/index.php?act=art&lang=no

http://www.website.org.uk/index.php?act=faq&lang=no

http://www.website.org.uk/index.php?act=hlp&lang=no

http://www.website.org.uk/index.php?act=con&lang=no

http://www.website.org.uk/index.php?ref=&lang=no

http://www.website.org.uk/index.php?ref=&lang=no&act=pre

http://www.website.org.uk/index.php?ref=&lang=no&act=art

http://www.website.org.uk/index.php?ref=&lang=no&act=faq

http://www.website.org.uk/index.php?ref=&lang=no&act=hlp

http://www.website.org.uk/index.php?ref=&lang=no&act=con

http://www.website.org.uk/index.php?ref=&lang=no&act=err

http://www.website.org.uk/content/languageBuild.php?lang=en

http://www.website.org.uk/index.php?act=err&lang=en

http://www.website.org.uk/index.php?act=err&lang=fr

http://www.website.org.uk/index.php?act=err&lang=de

http://www.website.org.uk/index.php?act=err&lang=es

http://www.website.org.uk/index.php?act=err&lang=it

http://www.website.org.uk/index.php?act=err&lang=sv

http://www.website.org.uk/index.php?act=err&lang=no



Sorry for the long list! Also I know that the URLs are #*$!, but what am I going to do about it :)
I just want to redirect them for now.

The new system should be much better for me.

g1smd

8:18 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your RewriteRules are the most inefficient they could ever possibly be.

Rule of thumb: NEVER use multiple (.*) patterns in a rule.

To find a match, each rule will need to make hundreds, maybe thousands, of "back off and retry" attempts before a match is found.

In most cases, patterns like
([^/]+)
or similar will parse a LOT faster.

So, the work will involve:
- Redirecting OLD URLs to the new "foldered" format
- Setting up Redirects such that direct access to the scripts is also redirected to the "foldered" URLs
- Setting up Rewrites for direct client requests for "foldered" URLs to connect to the server internal "path to the script" to serve that content.

The last item is vital for the site to work. The other two are vital to prevent Duplicate Content issues.

All of the rules should use Mod_Rewrite RewriteRule code. Do not use Redirect or RedirectMatch here. Redirects will contain domain name and [R=301,L] flags. Rewrites will use the [L] flag and contain no domain name.

Finally, the links on the pages of your site must be changed to point to those new "foldered" URLs. It is those links that "define" the URLs of your site.

MNeMiC

8:25 am on Apr 16, 2010 (gmt 0)

10+ Year Member



Thanks for the tip with the (.*), I changed the ones I actually needed to ([^/]+) and the ones that are rarely changed to what I actually needed. (case1|case2|case3)/(subcase1|subcase2|subcase3)


The new page is up and running and it works quite well with the new URLs. So the third step is done.

What method should I use to restrict access to the .php-files directly? I may have some .php files that I want to be able to access, and I've setup code that will keep users away from the admin-type .php-files. Do I still need step 2?

I tried something like:
#RewriteRule (.+)\.php$ index.php

But it's not working


The one I've been having most trouble with is the first one, to redirect the OLD system to the new one.

As the URLs use ? and = and & to control the page content it cannot be solved by a RewriteRule or a Redirect/RedirectMatch alone as far as I've learned.

That's why I need the RewriteCond, which I don't fully understand. It's slightly too technical for me.


I have tried literally hundreds of combinations and it's still not working at all for me with the old URLs.


#RewriteCond %{QUERY_STRING} Term=([a-zA-Z]*) 
#RewriteRule ^test\.php$ /test?%1


#RewriteCond %{QUERY_STRING} ^&act=pre$
#RewriteRule ^index\.php$ /francais/press/%1


#RewriteCond %{QUERY_STRING} act=(.*)
#RewriteRule ^index.php(.*) /index.php?page=%1 [R]

MNeMiC

11:51 am on Apr 16, 2010 (gmt 0)

10+ Year Member



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.example.com/subdir/index.php?act=pre

Where would that take me?

[edited by: jdMorgan at 4:19 pm (utc) on Apr 16, 2010]
[edit reason] example.com, disabled smilies in code [/edit]

jdMorgan

4:26 pm on Apr 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you put this code into /subdir/.htaccess, it would take you to /english/press/?act=pre
If you put this code into /.htaccess, the rule pattern would not match, so the rule would not be invoked.

Rather than asking about what each of many proposed rules might do, I'd suggest presenting a short representative list of old URLs, and showing the desired disposition of each. That will be helpful in retaining the interest of members who might be willing to help, but who are pressed for time, and cannot dig through the preceding posts to extract the details needed to understand the current problem.

Focus on one question at a time, and try to provide all details and context in one post with that question.

Thanks,
Jim

MNeMiC

9:37 pm on Apr 16, 2010 (gmt 0)

10+ Year Member



Hi, thanks for the tip, I'll keep that in mind.

Okay so the goal here is to update an existing page to a new version. The pages work the same but have different queries.

I want to match the old queries to the new ones to avoid having dead links from the old page.

Here are a couple of examples of what I'm trying to achieve:

http://www.website.org.uk/index.php?act=&lang=sv
to
http://www.website.org.uk/svenska/home/

http://www.website.org.uk/index.php?act=hlp&lang=en
to
http://www.website.org.uk/english/help/

http://www.website.org.uk/index.php?ref=&lang=es&act=pre
to
http://www.website.org.uk/espanol/press/

http://www.website.org.uk/index.php?act=faq&lang=no
to
http://www.website.org.uk/norsk/faq/


This is in the .htaccess which is in this folder-structure:

/ROOT/
.htaccess
/public_html/
/subdir/

Essentially what should work is just replacing the query values like this:

act=pre to page=press
act=art to page=articles
act=faq to page=faq
act=hlp to page=help
act=con to page=contact
act=err to page=error
act=emg to page=emg

lang=en to language=english
lang=fr to language=francais
lang=de to language=deutch
lang=es to language=espanol
lang=it to language=italiano
lang=sv to language=svenska
lang=no to language=norsk


Is there a way to achieve it like that? Or should I just rewrite all the old URLs (about 110 so that's fine with me, but I can't get the code for it to work as it's query-based).

What I have for this is the system like this:
RewriteCond %{QUERY_STRING} (^|&)act=pre(&|$)
RewriteRule ^index\.php$ svenska/press/%1 [R]


Thanks for taking your time! I really appreciate it, I've been at this problem for 15+ hours of testing now, it's driving me nuts :)

[edited by: jdMorgan at 12:16 am (utc) on Apr 17, 2010]
[edit reason] Disabled smilies in code. [/edit]

jdMorgan

12:11 am on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably easiest to write and to maintain with two chained rules and a user-defined variable:

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.example.com/%{ENV:qLang}/%3/? [R=301,L]

Note that the ">" character is just an arbitrary delimiter used to facilitate parsing the query string and replacement values in the RewriteConds. You could use any other 'rare' character that is not a regex operator and will never appear in a valid query string, such as "~".

This chained rule will only be invoked if both parameters are present (in any order).

[added] If you have server config access, by all means look into using a RewriteMap defined in httpd.conf or one of the other config files, instead of this .htaccess solution. [/added]

Jim

MNeMiC

9:25 am on Apr 17, 2010 (gmt 0)

10+ Year Member



Wow! That worked wonderful! Thank you so much.
I had to move the .htaccess away from the root level to the domain-level, and re-write some of my old codes for it to work properly from there but it solved it!

Thanks to that I managed to solve all my other problems as well including transfer from http:// to [www....] and making it work with or without a trailing slash and forcing a trailing slash.

All I had to do now was to make it work without having both, which was as simple as copying your code without the ${ENV:qLan} variable.


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 [#...] # #
RewriteCond %{HTTP_HOST} ^website\.org.uk$
RewriteRule (.*)
http://www.website.org.uk/$1
[R=301,L]
# # #Redirect http:// to [#...] # #
#########################################

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

[edited by: jdMorgan at 1:04 am (utc) on Apr 18, 2010]
[edit reason] Disabled smilies in code [/edit]

g1smd

8:06 pm on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{HTTP_HOST} ^website\.org.uk$
would be better coded as

RewriteCond %{HTTP_HOST} [b]![/b]^[b](www\.[/b]website[b]\[/b].org[b]\[/b].uk[b])?[/b]$


as it then also fixes URL requests with appended port numbers, etc.


Remove the multiple # in comments. One # is enough.


The 'add slashes' code should be placed before the 'non-www to www' code. Think about a non-www URL request without slashes. Your code will first redirect to www and then redirect again to add the slash. With the rules reversed the unwanted 'redirection chain' is eliminated.

MNeMiC

8:57 pm on Apr 18, 2010 (gmt 0)

10+ Year Member



Oh! Great pointers! Thanks for the tips there, I'm sure they'll save quite some performance!