.htaccess URL屏蔽而不是重定向 [英] .htaccess URL masking instead of redirecting

查看:67
本文介绍了.htaccess URL屏蔽而不是重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to mask URL in away like while the real URL is www.somedomain.com/subfolder/index.php?p=page3 it shows www.somedomain.com/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.com/subfolder/$1?[R = 301,L]

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^index.php$ %{QUERY_STRING} [C]
RewriteRule p=(.*) www.somedomain.com/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.com/subfolder/ 的索引页时,上面的代码也给出了500个服务器错误.

Also the code above gives a 500 server error when I launch the index page of the subfolder www.somedomain.com/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]

静默映射:

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

http://www.somedomain.com/anyfolder/val with or without trailing slash.

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

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

收件人:

http://www.somedomain.com/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屏蔽而不是重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆