dongwang3066 2015-03-13 05:39
浏览 18
已采纳

.htaccess网址中的漂亮网址标题

I'm trying to make pretty url but want to put content title in url instead id, then i put content title in url with query string:

index.php?action=content&id=22

changed to:

index.php?action=content&title=stack-over-flow

it's works fine. now i trying to make it pretty but got a problem in htaccess code.

before removing id in url code was:

RewriteRule ^([a-z]+)/([0-9]+)/?$ index.php?action=$1&id=$2 [NC,L,QSA]

then i changed to:

RewriteRule ^([a-z]+)/([a-z]+)/?$ content.php?action=$1&title=$2 [NC,L,QSA]

but it's not working and i will back 300 Multiple Choices page. well, i think it's a httaccess problem, but i'm new in htaccess, need a hand to fix this.

want this:

/content/stack-over-flow

  • 写回答

1条回答 默认 最新

  • douben8492 2015-03-13 05:41
    关注

    Your regex is only allowing letters. It should also allow hyphen, numbers, upper case letters and underscore. Try this:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-z]+)/([^/]+)/?$ content.php?action=$1&title=$2 [NC,L,QSA]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部