# /handbags.php to /departments/handbags-luggage/

New to mod_rewrite? This is a good place to start.

# /handbags.php to /departments/handbags-luggage/

Postby dazzclub » Fri Sep 18, 2009 2:03 am

Hi there,

I've got several department pages like this;

menswear.php
homeware.php
footwear.php
etc....

Normally accessed this way. http://www.website.com/menswear.php

If possible i would like to have this instead. http://www.website.com/departments/menswear/

Here is my current rewrite code but I havent had any luck
Code: Select all
Options +FollowSymLinks
RewriteEngine On
# /menswear.php to /departments/menswear/
RewriteRule ^(menswear)\.php$ departments/menswear[L]


Any pointers you guys can give to help me out...

Thanks
dazzclub
 
Posts: 3
Joined: Thu Sep 17, 2009 7:22 am
Location: Hull

Postby richardk » Fri Sep 18, 2009 9:20 am

Match the URL that you want in the browser's address bar and rewrite to the working URL.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /departments/menswear/ to /menswear.php
RewriteRule ^departments/menswear/?$ /menswear.php [L]

Make sure you leave a space before the flags ([L]).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby dazzclub » Fri Sep 18, 2009 4:52 pm

Hi Richard thanks for getting back to me..

may i ask you a question please...

I've looked at your code and in it says # /departments/menswear/ to /menswear.php


and reading what your wrote,
matching the url would be /menswear.php (thats where the page is actually located) and then rewriting it would be /departments/menswear/ (this is what i want to display in the browser)

is that correct or have i miss understood you..

or was you simply implying in the above statement that fake url actually leads to real page

If i've confused i apologise...

Thanks
dazzclub
 
Posts: 3
Joined: Thu Sep 17, 2009 7:22 am
Location: Hull

Postby richardk » Sat Sep 19, 2009 7:50 am

You have interpreted it the wrong way round.

matching the url would be /menswear.php (thats where the page is actually located)

"Match the URL that you want in the browser's address bar" ie. you want the user to see /departments/menswear/.

then rewriting it would be /departments/menswear/

"and rewrite to the working URL. " ie. /menswear.php currently works.

Try the mod_rewrite i posted. What happens when you go to /departments/menswear/?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby dazzclub » Mon Sep 21, 2009 12:47 am

Hi Richard so sorry about that...

ok, i have copied and pasted the code you supplied but just changed departments
Code: Select all
Options +FollowSymLinks

RewriteEngine On

#changed menswear to handbags
# /departments/handbags/ to /handbags.php
RewriteRule ^departments/handbags/?$ /handbags.php[L]


When i type in http://localhost/project/departments/handbags/

The browser displays Not Found 404 The requested URL /handbags.php was not found on this server.

More info
I have placed the .htaccess on the same level as the actual handbags.php file

Thank you for your continued help on this, i appreaciate this
dazzclub
 
Posts: 3
Joined: Thu Sep 17, 2009 7:22 am
Location: Hull

Postby richardk » Mon Sep 21, 2009 10:28 am

The error says it all, you need
Code: Select all
/project/handbags.php

or
Code: Select all
./handbags.php

(relative) instead of
Code: Select all
/handbags.php
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

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

cron