Htaccess help- moving from html site -> php

G’day,

I need some help with changing all incoming requests to my site eg

http://www.mysite.com/green-lantern.html

to now go to

http://www.mysite.com/search.php?spsp_search=green+lantern

Due to the size/age of the site there may be approximately 300K+ pages so need to do this properly.

I am unsure how to make sure the htaccess rewrite can cater for all the urls including the short and extra long ones:
eg

http://www.mysite.com/lantern.html

and

http://www.mysite.com/green-lantern-children-pyjamas.html

to become

http://www.mysite.com/search.php?spsp_search=green

and

http://www.mysite.com/search.php?spsp_search=green+lantern+children+pyjamas

Your help is appreciated.

Rémon,

Au contraire, mon ami! It is possible as the Next flag will run back through to catch the next instance so one Rule to rule them all! However, indeed, the order is important and should be as shown (for the one Rule with Next flag first) followed by the URI move to query string.

Regards,

DK

Just about midnight here: am starting @

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-z]+)\\.html$ search.php?spsp_search=$1 [L]

will continue tomorrow as need to get some sleep in for work.

Thanks.

That’s where my head started to hurt - thinking multiple rules may have been needed for the number of dashes.

Am trying to figure out how the last post works - will get some preliminary testing done now and tomorrow night.

Claudek,

Have a look at the tutorial linked in my signature. There are coding examples for (1) capturing the query string and (2) for converting one character to another. THEN, please show us the code you assemble from the examples and I’ll help you get through it.

Just be sure that ScallioXTX’s comments are taken to heart - green-lantern => green+lantern, not lantern => green!

Regards,

DK

Except for the green/lantern confusion it was perfectly ledgible :slight_smile:
Have you taken a look at the article dklynn pointed you to, http://datakoncepts.com/seo and tried something for yourself?

Hello All,
That was a typo from my side - all names will remain the same except for the url and the + and -
Had only 2 hours sleep when I wrote that so am surprised it was actually legible to be honest.

So it will be website.com/lantern changing to website.com/search.php?spsp_search=lantern

You are on the right track! What you need to do now is replace dashes with pluses. See the section “Replace A Character” in the article on how to do this: http://datakoncepts.com/seo#example-1

Note that AFAIK it’s not possible to replace all dashes with pluses in one RewriteRule, so you’ll need something like

RewriteRule to replace 4 dashes with minuses
RewriteRule to replace 3 dashes with minuses
RewriteRule to replace 2 dashes with minuses
RewriteRule to replace 1 dash with a minus
RewriteRule to replace a URL with 0 dashes

In this example I start with 4, but this depends on your situation. If you also have URLs that have more than 4 dashes you need to make sure you take these into account as well.

Does that make sense?

So basically what you’re saying is for a URL /some-term-with-dashes-in-it should be rewritten to /search.php?spsp_search=some+term+with+dashes+in+it ?
i.e. for any URL in the root of the website replace the dashes with pluses and feed that as a parameter to /search.php ?

I’m not really sure what the last rules you wrote means. Did you really want to rewrite [noparse]http://www.mysite.com/[/noparse][color=“blue”]lantern.html[/color] to [noparse]http://www.mysite.com/search.php?spsp_search=[/noparse][color=“blue”]green[/color] ?
If so, you can’t used a fixed set of rules for those kinds of URLs, but you need to hard-code all of them (using mod_alias)

Rémon and I had a chat about this and, when I showed him the code, he got it (he was going at replacing the -'s in the query string which is much more difficult)!

RewriteEngine on
RewriteRule ^/?(.*)-(.*)$ $1+$2 [N,L]
RewriteRule ^([a-z+]+)\\.html$ search.php?spsp_search=$1 [L]

What this does is to replace all -'s with +'s in the {REQUEST_URI} string then match the lowercase letters and +'s.html and send that to the query string as the value of spsp-search.

Regards,

DK