xingkid 2012-03-05 02:08:02 2890次浏览 2条回复 0 0 0

有个问题折腾我一晚上了。 我想把这样的URL: localhost/project/questions/detail/id/123.html 重写成localhost/project/questions/detail-123.html 不过试了大半个晚上都没能成功 隐藏index.php和添加html后缀我都成功了,就是重写这个丝毫没办法。 我的项目是在网站根目录的project文件夹。 尝试改写的是project目录下的.htaccess

参考网上的做法我觉得应该正确的写法是这样的

 Options +FollowSymLinks
 IndexIgnore */*
 RewriteEngine on
 
 # if a directory or a file exists, use it directly
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 # otherwise forward it to index.php
 RewriteRule . index.php

RewriteRule ^(.*)/detail-([0-9]+).html$ $1/detail/id/$2.html

但是实在无法成功,如有人解决过类似问题,希望能帮帮忙!谢谢

  • 回复于 2012-03-05 02:32 举报

    第二个RewriteRule前面要加上
    RewriteCond %{QUERY_STRING} ^(.*)$

  • 回复于 2012-03-08 15:57 举报

    这个说的不对。
    经过我长时间的尝试,总算解决了问题。
    在httpd.conf中写入
    RewriteRule ^(.*)/detail-([0-9]+)\.html$ $1/detail/id/$2.html [NC, P, R=301]
    还需要额外打开proxy和http_proxy模块,否则P选项启动代理功能失败导致出错。

您需要登录后才可以回复。登录 | 立即注册