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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 TensorFlow深度学习拓展项目
    • ¥20 springboot博客系统
    • ¥15 关于#c++#的问题:在A和B类中应该怎么定义复制构造函数来避开unordered_set复制构造的问题(相关搜索:头文件)
    • ¥15 MICE包多重插补后数据集汇总导出
    • ¥15 一道算法分析问题(关于3-MSAT)
    • ¥15 C++ FLUENT 化学反应速率 编写困难
    • ¥15 Python嵌套交叉验证
    • ¥15 linuxkit+elasticsearch
    • ¥15 兄得萌6.13do题😭😭大一小东西的work
    • ¥15 投不到原始数据,gdal投影代码