du970294 2012-04-10 19:40
浏览 49
已采纳

apache中的mod_rewrite条件,以删除.php不能按预期工作

RewriteEngine On

RewriteRule ^/showlisting/(.*)$ showlisting.php/$1 [L]
RewriteRule ^/listings/(.*)$ listings.php/$1 [L]

RewriteCond %{HTTP_HOST} ^mydomain\.
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

ErrorDocument 404 /notfound

In the above, this is what I want to achieve:

  1. I want to forward any URLs such as www.mydomain.com/showlisting/my-listing-data/with-more-slashes/and-some-text to show the content of www.mydomain.com/showlisting*.php*/my-listing-data/with-more-slashes/and-some-text but with URL masking so that the .php does NOT appear on the browser window.
  2. I also want to append with www when the www is not present in the request for SEO purposes, although I'm not sure how important this is these days.

When I visit www.mydomain.com/showlisting/my-listing-data/with-more-slashes/and-some-text however it shows a 404 error, but with the .php added to showlisting, it works fine. Any ideas?

However note that the appending of the www. works fine - that's not the part I'm struggling with, although I included that part of the code anyway for full analysis.

  • 写回答

1条回答 默认 最新

  • dpq59734 2012-04-10 19:50
    关注

    Maybe

    RewriteEngine On
    
    RewriteRule ^showlisting/(.*)$ showlisting.php/$1 [L]
    RewriteRule ^listings/(.*)$ listings.php/$1 [L]
    
    RewriteCond %{HTTP_HOST} ^mydomain\.
    RewriteRule ^$ http://www.mydomain.com/ [R=301,L]
    
    ErrorDocument 404 /notfound
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了