dongwang3066 2015-03-13 13: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 13: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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作