Forum Moderators: phranque

Message Too Old, No Replies

Removing php variables from URL.

         

impfut

2:58 pm on Dec 10, 2010 (gmt 0)

10+ Year Member



Hello,

I'm working on a site that has a navigation structure as follows:
www.mysite.com/?parent=services&child=design&page=overview

I am currently converting the above to this:
www.mysite.com/parent/services/child/design/page/overview
Using...
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([^/=]+)=([^/]*)(/(.+))?$ /$4?$1=$2 [N,QSA]
RewriteRule ^([^/=]+)/([^/=]+)(/(.+))?$ /$4?$1=$2 [N,QSA]
RewriteRule ^([^/=]+)(/(.+))?$ /$3?$1 [N,QSA]


I need to be able to change it to:
www.mysite.com/services/design/overview

The site has over 100 pages so the URL's change e.g. "www.mysite.com/company/about/history" but there are always 3 levels ($parent $child $page).

Is this possible? It's really annoying me, I can't get it to work. Can anyone help me out please!

Cheers
Dave

impfut

7:14 pm on Dec 10, 2010 (gmt 0)

10+ Year Member



Have I asked a stupid question?

g1smd

7:40 pm on Dec 10, 2010 (gmt 0)

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



If URLs with parameter parts are already indexed, you need this redirect:

RewriteCond {%THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?parent=([^&]*)&child=([^&]+*)&page=([^&]*)\ HTTP/
RewriteRule ^(index\.php)?$ http://www.example.com/%1/%2/%3 [R=301,L]



If URLs with 6 path parts are already indexed, you also need this redirect:

RewriteRule ^parent/([^/]+)/child/([^/]+)/page/([^.]+) http://www.example.com/$1/$2/$3 [R=301,L]



and then you need something like this rewrite for that new three-level URL:

RewriteRule ^([^/]+)/([^/]+)/([^/.]+)$ /index.php?parent=$1&child=$2&page=$3 [L]

impfut

8:01 pm on Dec 10, 2010 (gmt 0)

10+ Year Member



Brilliant! g1smd you are my hero!

Many thanks bud.
Dave

g1smd

9:33 pm on Dec 10, 2010 (gmt 0)

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



Carefully test the code, and use Live HTTP Headers to ensure correct operation.

Clear browser cache before each test.

You will also need to add the usual non-www to www canonicalisation rules, just before the rewrite.