Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

php - htaccess pretty urls setup

I'm using htaccess for the first time to make pretty urls for my website html files and 1 php file. I was just wondering if I would be able to get some advice on my htaccess file set up and if how I have it set up is a good way? I'd hate for my urls to not work in some situation because of what I have written. :(

Example html file:

before:  http://www.domain.com/subdomain/htmlpage.html
after:   http://www.domain.com/subdomain/htmlpage/

Single php file:

before:  http://www.domain.com/subdomain/phppage.php?p=1
after:   http://www.domain.com/subdomain/phppage/1/

I have added in a rule to redirect index.html to index.php. I've also had to add 'base href' in the head of each file because I've used relative links.

the htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index.html?$ / [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]
RewriteRule ^(.+)/([0-9]+)/?$ phppage.php?p=$1 [L]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This line

RewriteRule ^(.+)/([0-9]+)/?$ phppage.php?p=$1 [L]

is going to send some pages to phppage.php even though they don't look like

http://www.domain.com/subdomain/phppage/1/

because there is no mention of phppage in the first argument to RewriteRule.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...