我想使用.htaccess隐藏我网站页面的网址参数

时间:2016-03-16 06:07:47

标签: php apache .htaccess mod-rewrite

  

http://eoflex/CAportal/readmore/?slug=blogtitle

我试图通过.htaccess文件隐藏url参数是否可以显示这样的url?

给我解决方案我是.htaccess文件的新手 我在下面给出的.htaccess文件中编写代码并且它不起作用,我想要像http://eoflex/CAportal/blogtitle这样的网址我不想显示/?slug = blogtitle *

 RewriteRule ^([A-Za-z0-9-]+)/?$ page.php?slug=$1 [L]

2 个答案:

答案 0 :(得分:4)

您可以在.htaccess文件中使用以下代码。你也可以使用apache重写模块。首先在apache服务器中启用apache重写模块。

在.htaccess文件中写下行

RewriteEngine On

RewriteRule ^ / CAportal / readmore /([a-zA-Z0-9 _-] +)/ $ /CAportal/readmore/page.php?slug=$1

<强> HINT

^ / read / This / Url / blogtitle /as/This/Url/page.php?slug=blogtitle

<强> INFO

^ 匹配字符串的开头

$ 匹配字符串的结尾

[0-9] 匹配一个数字,0-9。 [2-4]将匹配数字2到4,包括在内。

[A-Z] 匹配小写字母a-z

[A-Z] 匹配大写字母A-Z

[A-Z0-9] 结合其中一些,这匹配字母a-z和数字0-9

答案 1 :(得分:0)

试试这个(把它放在文件根目录中的.htaccess中)。

RewriteRule ^CAportal/readmore/([a-zA-Z0-9_-]+)/?$ /CAPortal/readmore/?slug=$1 [L]