catch only last variable

Discuss practical ways rearrange URLs using mod_rewrite.

catch only last variable

Postby OrT » Wed May 06, 2009 2:12 am

Hi all,

Kudos on the forum, very helpful people.

What I would like to do is only look at the last /item, for example:

www.domain.com/one/two/three/four(/)
-> only catch the 'four'.

The number of items before the last one is variable.

Also I need to pass HTTP variables with www.domain.com/one/two/?p=bla.

Any assistance is very much appreciated indeed!
OrT
 
Posts: 3
Joined: Tue May 05, 2009 6:27 am

Postby richardk » Wed May 06, 2009 9:26 am

Also I need to pass HTTP variables with www.domain.com/one/two/?p=bla.

Do you mean p=bla?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.+/)?([^/]+)/?$ /somewhere?last=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby OrT » Fri May 08, 2009 3:03 am

Thanks a lot, richardk, that did the trick nicely. Much appreciated.

Now, a new problem for you guys to sink your teeth in!

www.domain.com/level1/level2?q=option1
needs to refer to www.domain.com/index.php?page=2&option=1

Any help is, yet again, humbly welcomed.
OrT
 
Posts: 3
Joined: Tue May 05, 2009 6:27 am

Postby richardk » Fri May 08, 2009 5:52 am

Where does page=2 come form?
Does 2 change?
Is it only for /level1/level2 only (that exact URL)?
Do level1 and level2 change?
Will it ever be more or less than two levels?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby OrT » Wed May 20, 2009 12:26 am

Appearantly it already did what I asked, very sorry :-)

One last problem with having only one level:

domain.com/?q=var does what it's supposed to (goes to index.php etc)
domain.com/sqdf?q=var gives an error

Thanks again!
OrT
 
Posts: 3
Joined: Tue May 05, 2009 6:27 am

Postby richardk » Wed May 20, 2009 8:28 am

domain.com/sqdf?q=var gives an error

What kind of error? An Apache 404 error? An error from your script? What URL should it go to?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 24 guests

cron