douguai6716 2013-10-02 09:01
浏览 19
已采纳

mod_rewrite不适用于干净的网址

I am using wamp server for my projects and have stuck in making the urls clean

currently my url address is like this

http://localhost/BookProjectFinal/booksdetails.php?pid=8

I want to make it like this

http://localhost/BookProjectFinal/booksdetails/8

What I am using in my .htaccess file is this

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ booksdetails.php?pid=$1
RewriteRule ^([a-zA-Z0-9]+)/$ booksdetails.php?pid=$1

But its not working its returning the whole url. What the problem with it? Thanks

  • 写回答

1条回答 默认 最新

  • dtsps2098 2013-10-02 09:12
    关注

    The RewriteBase parameter will tell mod_rewrite from which directory to start matching. This can be used for applications that live in subfolders of apache. You may want to set it to /BookProjectFinal/ here.

    Your regexp is looking to match a complete alphanumeric URL optionally followed by a slash, which I'm not sure is what you want. Try something like:

    RewriteRule bookdetails/([0-9]+) bookdetails.php?pid=$1
    

    to match only the number. Here's a test:

    RewriteEngine On
    RewriteRule ^bookdetails/([0-9]+) bookdetails.php?a=b&pid=$1
    

    Matches URLs of the form /bookdetails/8. Use print_r($_GET) to sanity check in bookdetails.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"
  • ¥20 基于决策树的数字信号处理,2ask 2psk 2fsk的代码,检查下报错的原因
  • ¥20 python作业求过程
  • ¥15 wincc已组态的变量过多
  • ¥60 如图:直线与椭圆X轴平行,求直线与椭圆任意一点的相切坐标计算公式
  • ¥50 如何用python使用opencv里的cv::cudacodec::VideoWriter函数对视频进行GPU硬编码
  • ¥100 c#solidworks 二次开发 工程图自动标边线法兰 等折弯尺寸怎么标
  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录