开发者

Mod-rewrite url from /example.php?id=1 to /example/title-of-page

I have a website that generates urls like:

www.site.com/example.php?id=开发者_StackOverflow社区1

I would like that url to be displayed like:

www.site.com/example/the-title-of-the-page-whatever-it-may-be

Can I do this in .htaccess or do I need to edit the php or what?

Be gentle, and treat me like an idiot please - I'm brand new to all this :)


If your using a apache server you can use mod rewrite


Use this for your htaccess :

RewriteEngine On
RewriteRule ^([^/]*).html$ /example.php?id=$1 [L]

Your Old URL > example.com/example.php?id=1
Will be change to > example.com/1.html

Using id :

RewriteEngine On
RewriteRule ^id/([^/]*).html$ /example.php?id=$1 [L]

Your Old URL > example.com/example.php?id=1
Will be change to > example.com/id/1.html

Hope Help you ;)


You indeed need an .htaccess file for this and of course some PHP code to see what page needs to be loaded. The .htaccess could look something like this:

# Start rewrite engine
RewriteEngine On

# Catch non existing files and/or folders (treat as optimized urls)
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Catch blocked folders (treat as optimized urls)
RewriteRule ^(.*)$ index.php [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜