如何使用.htacess从地址栏隐藏网址

时间:2017-04-22 11:00:34

标签: php regex .htaccess url-rewriting

我一直在网上搜索这个,但我没有运气。我找到了一些答案,但没有任何帮助

我不知道如何使用.htacess,但我找到了这段代码

   RewriteEngine on

# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]

# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" 
RewriteRule .* - [L,R=404]

# NOTE! FOR APACHE ON WINDOWS: Add [NC] to RewriteCond like this:
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]

它似乎阻止了除索引

之外的所有页面

http://www.skymount.in/mega_menu.php?id=%27503732-u_submenuid%27
这是链接 我希望它看起来像 http://www.skymount.in/mega_menu.php
或者是 http://www.skymount.in/mega_menu

请帮助

2 个答案:

答案 0 :(得分:0)

$ 1表示“使用原始网址的第一个捕获部分”。为了捕获原始URL的一部分,您需要使用括号来捕获它。像这样:

RewriteRule ^/mega_menu/(.*) /$1

这意味着“接受以/ mega_menu /开头的任何内容,然后捕获后面的内容并将其放入变量$ 1.重写为$ 1变量并附加原始查询字符串。

我希望它可以帮到你!

答案 1 :(得分:-1)

将此作为整个.htaccess文件内容使用:

RewriteEngine on
RewriteRule ^mega_menu\.php$ mega_menu.php?id=%27503732-u_submenuid%27 [NC]
相关问题