我正试图隐藏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屏蔽而不是重定向
发布评论