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
165 views
in Technique[技术] by (71.8m points)

php - How to format URL on Website with htaccess

I would like some help in formatting a url so that it is more SEO friendly. So the url is formatted below

www.portfolio.com/workDetails?url=work-title-here

but I would like the format to be

www.portfolio.com/work/work-title-here

I've tried the following

RewriteEngine on
RewriteRule ^/work/([0-9]+).html /workDetail.php?url=$1

But I got a 500x error

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

This page appears to have a solution to what you are trying to do:

<?
    $Params = explode( '/', $PATH_INFO );

    while( list( $Index, $Value ) = each( $Params )) {
        echo "Params[ $Index ] = $Value<BR>
" );
    }
?>

Hit this URL:

http://whatever.site.com/ThisIsAProgram/these/directories/are/not/real

You should get:

Params[ 0 ] =

Params[ 1 ] = these

Params[ 2 ] = directories

Params[ 3 ] = are

Params[ 4 ] = not

Params[ 5 ] = real

And to display the PHP file as just the file name, try this:

Options +MultiViews
RewriteEngine On

RewriteCond %{THE_REQUEST} /([^.]+).php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]

EDIT: If you are wanting a more complete example, this answer covers it a lot more in depth than I could. This will definitely help you cover all your bases and understand the issue if my other linked article doesn't make it clear enough.


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

...