getting only part of a url

Helicon Ape provides support for Apache .htacces and .htpasswd configuration files for Microsoft IIS.
User avatar
Posts: 10
Joined: 17 Jun 2012, 07:25

getting only part of a url

04 Jul 2012, 11:11

Hello All,

I am slowly getting to grips with this:

say i have the following url:

h t t p : / / domain.com/zone1/zone2/zone3/index.html

or

h t t p : / / domain.com/zone1/zone2/zone3/zone4/index.html


How can I get the last zone before the /index.html, there can be any amount of zones as shown above

Thanks,

Andy

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: getting only part of a url

05 Jul 2012, 06:21

Hello,

Not sure I understand. What is the initial request and what is the desired result?

Regards
Andrew

User avatar
Posts: 10
Joined: 17 Jun 2012, 07:25

Re: getting only part of a url

05 Jul 2012, 06:37

Hello Andrew,

OK I will try an explain it a little better.

Say I have this url
http://domain.com/iMac Parts/iMac_Intel_Parts/iMac_17-inch_Late_2006_CD/products.html

basically I want to be able to use the "iMac_17-inch_Late_2006_CD" from the link to get the id from the database.

but the url could have different depths for example:

http://domain.com/Mac_Mini_Parts/Mac_mi ... ducts.html


Andrew

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: getting only part of a url

05 Jul 2012, 07:10

So the regular expression would be:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteRule ^.*/([^/]+)/products\.html$ /$1 [NC,L]


Regards
Andrew

Return to Helicon Ape

Who is online

Users browsing this forum: No registered users and 24 guests