.htaccess URL屏蔽而不是重定向

编程入门 行业动态 更新时间:2024-10-22 20:29:43
本文介绍了.htaccess URL屏蔽而不是重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正试图隐藏URL,就像真实URL是 www.somedomain/subfolder/index.php?p=page3 一样,它显示 www.somedomain/subfolder/page3 ,我知道在这里已经问过很多这样的问题,我确实搜索了很多,但是大多数结果都无法满足我的要求在寻找,我也几乎什么都不知道,但是关于htaccess调整的基本知识.

I'm trying to mask URL in away like while the real URL is www.somedomain/subfolder/index.php?p=page3 it shows www.somedomain/subfolder/page3 , I know such questions have been asked a lot on here and I did searched a lot but most of results didn't cater what I am looking for, also I almost know nothing but the basics about htaccess tweaking.

我搜索时得到的一个结果具有以下htaccess代码:

one result I got when i searched has the following htaccess code:

选项+ FollowSymLinks 选项+索引RewriteEngine开启RewriteRule ^ index.php $%{QUERY_STRING} [C] RewriteRule p =(.*)www.somedomain/subfolder/$1?[R = 301,L]

Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteRule ^index.php$ %{QUERY_STRING} [C] RewriteRule p=(.*) www.somedomain/subfolder/$1? [R=301,L]

它确实完成了有关URL重写的技巧,但它重定向了页面而不是仅仅屏蔽URL,即使我删除了R = 301,它也仍然显示404错误.

It did the trick concerning the URL re-writing but it redirects the page instead of just masking the URL and it gives a 404 error, even when I removed the R=301 it didn't work.

当我启动子文件夹 www.somedomain/subfolder/ 的索引页时,上面的代码也给出了500个服务器错误.

Also the code above gives a 500 server error when I launch the index page of the subfolder www.somedomain/subfolder/.

最后我想提到的是,我正在本地主机中的子目录进行测试,以防它们有所不同,因为我在网上找到的某些代码根本无法工作,或者它们提供了500台服务器错误.

Finally I'd like to mention that I'm testing with a sub-directory in localhost in case it make difference because some codes I've found on the web either just don't work at all or they give 500 server error.

非常感谢.

推荐答案

您可以尝试以下方法:

Options +FollowSymlinks RewriteEngine On RewriteBase / # Prevent loops RewriteCond %{REQUEST_URI} !index\.php [NC] RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/? [NC] RewriteRule .* %1/index.php?page=%2 [L]

静默映射:

www.somedomain/anyfolder/val (带有或不带有斜杠).

www.somedomain/anyfolder/val with or without trailing slash.

上面是在浏览器的地址栏中输入并显示的URL.

The above is the URL entered and shown in the browser's address bar.

收件人:

www.somedomain/anyfolder/index.php?p=val

字符串 anyfolder 和 val 被认为是动态的.

Strings anyfolder and val are assumed to be dynamic.

要进行永久重定向,请将 [L] 替换为 [R = 301,L] .

For permanent redirection, replace [L] with [R=301,L].

更多推荐

.htaccess URL屏蔽而不是重定向

本文发布于:2023-10-31 13:00:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546159.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:屏蔽   而不是   重定向   htaccess   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!