help with clean URL's

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

help with clean URL's

Postby stvwlf » Sun May 10, 2009 2:23 am

hi - appreciate help creating clean url's.

clean URL is
http://domain.com/portfolio/type/page
where portfolio is an actual folder,
type is one of identity, web, print
page is a number

real url to be
http://domain.com/portfolio/portfolio.p ... $1&page=$2

.htaccess to go in http://domain.com/portfolio/

type is optional on clean URL - if not specified, on real URL type defaults to "identity"
type is alphanumeric a-z and 0-9

page is optional on clean URL - if not specified, on real URL page defaults to 1
page is numeric 1 - 99

thanks very much!
stvwlf
 
Posts: 5
Joined: Sun May 10, 2009 1:49 am

Postby richardk » Sun May 10, 2009 2:31 pm

type is one of identity, web, print
...
type is alphanumeric a-z and 0-9

Which one is correct?

type is optional on clean URL - if not specified, on real URL type defaults to "identity"

For /portfolio/, /portfolio/page/, both or neither?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([0-9]+)/?$ ./portfolio.php?type=identity&page=$1 [QSA,L]
RewriteRule ^(identity|print|web)(?:/([0-9]+))?/?$ ./portfolio.php?type=$1&page=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby stvwlf » Sun May 10, 2009 11:11 pm

Hi

Thank you very much. This is working well, with one exception (below)

Quote:
type is one of identity, web, print
...
type is alphanumeric a-z and 0-9

Which one is correct?


I tried SO hard to be accurate and still screwed it up. testing for the specific values of Type is best, which is what you used, and its working correctly. Your other question doesn't need an answer since what you did is working fine.

=================
The one thing not working completely right with the code you gave me is, if the specified URL is just http://domain.com/portfolio/, Apache sees a folder named /portfolio/, and is creating a 403 on that folder instead of redirecting to the PHP file.

When just http://domain.com/portfolio/ is specified, I'd like it to redirect to /portfolio/portfolio.php, with no parameters. I'll have the PHP handle that situation. Could you please add that one change to the code you wrote, which was

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([0-9]+)/?$ ./portfolio.php?type=identity&page=$1 [QSA,L]
RewriteRule ^(identity|print|web)(?:/([0-9]+))?/?$ ./portfolio.php?type=$1&page=$2 [QSA,L]


thank you very much
stvwlf
 
Posts: 5
Joined: Sun May 10, 2009 1:49 am

Postby richardk » Mon May 11, 2009 8:41 am

I tried SO hard to be accurate and still screwed it up.

At least you tried.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^$ ./portfolio.php [QSA,L]
RewriteRule ^([0-9]+)/?$ ./portfolio.php?type=identity&page=$1 [QSA,L]
RewriteRule ^(identity|print|web)(?:/([0-9]+))?/?$ ./portfolio.php?type=$1&page=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby stvwlf » Mon May 11, 2009 9:22 am

Hi - yes, that is doing exactly what's needed

much appreciated
stvwlf
 
Posts: 5
Joined: Sun May 10, 2009 1:49 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 8 guests

cron