【问题标题】:How to fix a mod_rewrite RewriteRule in HTACCESS如何修复 HTACCESS 中的 mod_rewrite RewriteRule
【发布时间】:2013-02-28 04:11:44
【问题描述】:

我正在编写一些 RewriteRules,而我最基本的重写返回 404 错误。这是我的代码:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule s/(.*)/(.*)/$ /page.php?s=$2 [NC,L]
RewriteRule ^submit/$ submit.php [R,L]

# Options All -Indexes

<files .htaccess>
order allow,deny
deny from all
</files>

RewriteRule ^submit/$ submit.php [R,L] 是我遇到问题的地方。 当我访问 domain.com/submit/ 时,我的服务器返回 404 错误,提示“在此服务器上找不到请求的 URL /submit/”。就像服务器甚至没有查看我的 HTACCESS 文件一样。其他 RewriteRules 运行良好。

我错过了什么吗?

【问题讨论】:

  • 您是想将/submit/ 重写为submit.php,还是将其重定向到那里?
  • 尝试在替换 URL 中添加 前导斜杠:从 submit.php/submit.php跨度>

标签: .htaccess mod-rewrite


【解决方案1】:

你可以试试这个:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !page\.php    [NC]
RewriteRule ^s/(.*)/(.*)/$ /page.php?s=$2 [NC,L]

RewriteCond %{REQUEST_URI} !submit\.php  [NC]
RewriteRule ^submit   submit.php         [R,L,NC]

根据问题中的信息,就是这样。

无法猜测第一条规则是什么,因为没有 URL 示例来确定正则表达式匹配的模式或脚本的位置。

第二条规则会发生类似的情况,因为无法确认脚本 (submit.php) 的位置,因为问题中没有 URL 示例。

【讨论】:

    猜你喜欢
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    相关资源
    最近更新 更多