【问题标题】:Redirection Issues in htaccesshtaccess 中的重定向问题
【发布时间】:2021-09-25 02:34:02
【问题描述】:

这是我的 .htacess,我可以删除 .php 扩展名,但它没有按照预期的输出工作(例如 https://localhost/shap/example.php 到 https://localhost/shap/example ) 它适用于 index.php 但它适用于其他 .php 页面,它被卡在重定向中 请帮我解决这个问题

错误获取:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Return 404 if original request is .php
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
# RewriteRule .* - [L,R=404]

RewriteRule ^index\.php$ https://localhost/shap/ [NC,R]

RewriteRule ^example\.php$ https://localhost/shap/example[R]
</IfModule>

【问题讨论】:

  • 如果您在浏览器中点击链接https://localhost/example/example.php,能否告诉我们?
  • 这是@RavinderSingh13的实际图像
  • 您正在点击链接https://localhost/shap/example 应该由后端的https://localhost/shap/example.php 链接提供服务?请确认一次。
  • 它是 eample.php 仅在后端,但是当我把这个 RewriteRule ^example\.php$ localhost/shap/example[R] 放在 htaccess 中删除它显示的上述错误。 @RavinderSingh13
  • 所以你在浏览器中点击https://localhost/example/example.php

标签: .htaccess redirect mod-rewrite url-rewriting friendly-url


【解决方案1】:

使用您显示的示例,请尝试遵循 htaccess 规则文件。确保保留 htaccess 文件根文件夹(与示例文件夹一起不在示例文件夹内)。

在测试 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteBase /example/
RewriteCond %{THE_REQUEST} \s/example/example\.php\s [NC]
RewriteRule ^ /example/example? [R=301,L]

RewriteRule ^(example)/(example)?$ $1/$2.php [NC,L]

【讨论】:

  • @Ashish_more,你的 htaccess 和 example.php 在哪里?请在这里给出完整的路径。
  • 它在示例文件夹@RavinderSingh13内
  • @Ashish_more,将 htaccess 与示例文件夹一起放在示例文件夹中,然后尝试一次?
  • @Ashish_more,如果此解决方案对您有帮助,请告诉我?
  • 成功了,谢谢@RavinderSingh13
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多