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 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 echarts图表制作