【问题标题】:mod_rewrite conditions in apache to remove .php not working as expectedapache 中的 mod_rewrite 条件以删除 .php 未按预期工作
【发布时间】:2023-03-31 04:44:01
【问题描述】:
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. 当 www 不存在于 SEO 请求中时,我还想附加 www,尽管我不确定这些天这有多重要。

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

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

【问题讨论】:

  • .htaccess 文件位于哪个目录?
  • 确保斜线同步。对于规则正则表达式,它要么 w/o,要么用于替换。
  • 一切都在 public_html 文件夹下。所有 .php 文件、.htaccess 等

标签: php .htaccess url mod-rewrite forwarding


【解决方案1】:

也许

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

【讨论】:

  • 不走运 - 根据您的规格更改它。我应该指定 www。附加效果很好。 .php 问题目前不起作用。
猜你喜欢
  • 2016-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
  • 2019-03-15
  • 1970-01-01
相关资源
最近更新 更多