PHP friendly URL with .htaccess -


my pages looks this:

www.mywebsite.com/work-view?id=1

www.mywebsite.com/work-view?id=2

www.mywebsite.com/work-view?id=3

and on...

how set them .htaccess?

www.mywebsite.com/work/1

www.mywebsite.com/work/2

www.mywebsite.com/work/3

i've tried this, doesn't work.

rewriterule work/(.*)/ work-view.php?id=$1 

edit:

here's new code i'm trying.

rewriteengine on  rewritecond %{request_filename} !-d rewritecond %{request_filename}\.php -f rewriterule ^(.*)$ $1.php  rewriterule ^/?work/([0-9]+)$ work-view.php?id=$1 [l] 

when check page /work-view?id=2 displays fine, when try enter /work/2 shows 500 internal server error. unfortunately on cpanel logs don't see error related issue, maybe because of hosting restrictions.

new edit:

arkascha answer works great, problem related css , in case when use .htaccess i've changed paths css , it's working great.

here's code works great too.

rewriterule   ^work/([0-9]+)/?$  work-view?id=$1    [nc,l]    # handle product requests   

just short hint on attempt mention @ end of question:

that pattern work/(.*)/ not match subject work/1. take @ trailing slash in pattern. instead should try ^/?work/([0-9]+)$ or similar:

rewriteengine on rewriterule ^/?work/([0-9]+)$ work-view.php?id=$1 [l] 

and more general note, point out since surprisingly many developers not seem aware @ issue: should use .htaccess style files if have to. far better alternative place such rewriting rules in real host configuration of http server. .htaccess style files notoriously error prone, hard debug , really slow server down, nothing. provided last option not have control on host configuration, example when using cheap hosting provider.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -