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 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?