.htaccess 如何使用htaccess重定向链接以获得更好的外观

.htaccess 如何使用htaccess重定向链接以获得更好的外观,.htaccess,redirect,.htaccess,Redirect,我使用它,但它不适用于双“GET”变量: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^index.html$ index.php [L] RewriteRule ^about.html$ index.php?do=about [L] RewriteRule ^blogs.html$ index.php?do=blogs [L] Rewri

我使用它,但它不适用于双“GET”变量:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.html$ index.php [L]
RewriteRule ^about.html$ index.php?do=about [L]
RewriteRule ^blogs.html$ index.php?do=blogs [L]
RewriteRule ^blogs/(.*).html$ index.php?do=blog&seo=$1 [L]

编辑:My index.php与OnePage应用程序类似

<?php
$do=$_GET['do'];
if(file_exists("components/".$do.".php")){
    require_once("components/".$do.".php");
}else{
    include("main.php");
}
?>

我想在index.php中执行所有进程

index.php查找“此处是否存在任何文件夹?”如果不包括do.php

如果存在,则在my index.php中获取do和require


它可以工作,但我的方向是转到字典中的/blogs(它不存在)文件。如果我想回到主页,看起来像是blogs/what is sass/index或blogs/index。我的主页链接是

问题不在于
.htaccess
指令,而在于相关的内部链接。相对链接由浏览器(客户端)相对于当前URL自然解析。如果您在URL
/blogs/what is sass
处链接到
索引
,则浏览器会将其解析为
/blogs/what is sass/index

您需要在HTML源中使用根相对URL(以斜杠开头)或绝对URL。例如:

<a href="/index">
请注意,
RewriteCond
(条件)指令仅适用于后面的第一条
RewriteRule
指令。但是,如果这些请求(即
/index.html
/about.html
/blogs.html
/blogs/.html
)都没有映射到物理文件,那么这两个条件是多余的,可以简单地删除


此外,您在整个问题和评论中都使用了
/blogs/what is sass
作为示例URL,但上面的指令仅匹配
/blogs/what is sass.html
格式的URL,并带有
.html
扩展名。(?)

你说的“不工作”到底是什么意思?你发布的指令与你所说的相反。。。它会将形式为
/blogs/what is sass.html
(注意
.html
扩展名)的URL重写为
/index.php?do=blog&seo=what is sass
。假设
.htaccess
文件中没有其他指令,并且该
.htaccess
位于文档根目录中。(?)My index.php的工作原理类似于一页应用程序
我想在我的index.php中执行所有过程。您的
.htaccess
文件中是否有其他指令?是的,我的所有页面都有很多指令。这是有效的,但我的方向是进入字典中的/blogs(它不存在)文件。如果我想回到主页,它看起来像是
blogs/what is sass/index
blogs/index
。我的主页链接是。这是一个很好的答案解释,谢谢你分享同样的欢呼声。
<?php
$do=$_GET['do'];
if(file_exists("components/".$do.".php")){
    require_once("components/".$do.".php");
}else{
    include("main.php");
}
?>
<a href="/index">
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.html$ index.php [L]
RewriteRule ^about.html$ index.php?do=about [L]
RewriteRule ^blogs.html$ index.php?do=blogs [L]
RewriteRule ^blogs/(.*).html$ index.php?do=blog&seo=$1 [L]