简体   繁体   English

.htaccess无法正常工作

[英].htaccess Won't Work Correctly

So I have a Rewrite in my .htaccess that works correctly with what I originally planned. 所以我的.htaccess中有一个Rewrite,可以正常使用我最初的计划。

RewriteEngine on
RewriteRule ^([^/]+)/?$ index.php?id=$1 [QSA]

I have index.php?id=4 going to /4/. 我有index.php?id = 4到/ 4 /。

The Problem 问题

If I try to go to another page though, it always brings me back to index.php. 如果我尝试去另一个页面,它总是把我带回index.php。 For example, I have a page called "Update.php". 例如,我有一个名为“Update.php”的页面。 If I go to update.php, I'm redirected to index.php 如果我去update.php,我会被重定向到index.php

Any suggestions? 有什么建议么?

Thanks in advance, 提前致谢,

Add this line 添加此行

RewriteCond %{REQUEST_FILENAME} !-f

Above your rule 高于你的规则

This only rewrites when the file doesn't exist 仅在文件不存在时重写

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #check if requested file not found
RewriteCond %{REQUEST_FILENAME} !-d #check if requested directory not found
RewriteRule ^([^/]+)/?$ index.php?id=$1 [QSA] #then apply the rule

The above rule first checks if requested URI not a real file and folder, then applying the rule, this prevents to redirect when opening existing file and folder. 上面的规则首先检查请求的URI是否不是真实的文件和文件夹,然后应用规则,这可以防止在打开现有文件和文件夹时重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM