douhunbei0166 2014-02-11 13:27
浏览 36
已采纳

简单的mod_rewrite不起作用

Im kinda new using htaccess and mod rewrite

I got every link to work as i want, but i have a problem when im trying to change the link for the forum everything goes kinda to hell..

This is my code

RewriteRule ^thread/([0-9]+)/([A-Za-z0-9]+)$ sidor/forum/showthread.php?threadID=$1&name=$2 [L]

When i try to get thread/1/forum it works perfectly but when i try to get a longer name like this
thread/2/cs-wont-work-for-me

The htaccess gets me a error 404..

And my links i change so (spaces) gets - and åäö gets aao

Anyone knows what the problem is?

Do you need more code? just post a comment and tell me that then i can try to give you a little more.

  • 写回答

2条回答 默认 最新

  • dougan1884 2014-02-11 13:29
    关注

    thread/2/cs-wont-work-for-me is not matched because you only check for alpha numeric characters ([A-Za-z0-9]+). Include dashes and any other characters you want to match to your regex. This should do what you want:

    ^thread/([0-9]+)/([A-Za-z0-9\-ÅÄÖåäö]+)$
    

    As a sidenote, I can really recommend htaccess tester to debug issues like this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错