Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm looking to make some cleaner urls so that it basically, the web address looks nicer.

currently my url looks like this .. ...co.uk/article.php?sport=football&id=23.. & title for the post could be.. erm .."this is the title"

i have been looking around the web and all over youtube trying to find a video to help as i hardly take any info in when i read stuff, so videos seems more productive for me. What i would like is my url to read something like...

...co.uk/sport/football/this-is-the-title .. and if it was another topic something like... ...co.uk/sport/tennis/this-is-another-title ...something nice and clean and tells people exactly what they're looking at. Also, i would like to have it so when its on pages, them pages dont have to have there extension added on so you dont have to put .php or .html on the end of the address as well...

See Question&Answers more detail:os

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

1 Answer

You must keep id also in the pretty URL like the URL structure of Stackoverflow here. So instead of: /sport/football/this-is-the-title have it like:

/sport/football/23/this-is-the-title

Once that is settled let's now look into establishing mod_rewrite code to achieve it.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^sport/([^/]+)/([^/]+)/([^/]+)/?$ /article.php?sport=$1&id=$2&title=$3 [L,QSA]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...