在 Apache 中mod_rewrite条件以删除.php无法按预期工作


mod_rewrite conditions in apache to remove .php not working as expected

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

在上面,这就是我想要实现的目标:

  1. 我想转发任何 URL www.mydomain.com/showlisting/my-listing-data/with-more-slashes/and-some-text 以显示 www.mydomain.com/showlisting*.php*/my-listing-data/with-more-slashes/and-some-text 的内容,但带有 URL 掩码,以便.php不会出现在浏览器窗口中。
  2. 出于 SEO 目的,当 www 未
  3. 出现在请求中时,我还想附加 www,尽管我不确定这些天这有多重要。

但是,当我访问 www.mydomain.com/showlisting/my-listing-data/with-more-slashes/and-some-text 时,它会显示404错误,但是将.php添加到显示列表中后,它工作正常。有什么想法吗?

但是请注意,www.的附加工作正常 - 这不是我正在努力的部分,尽管我无论如何都包含了这部分代码以进行全面分析。

也许

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