设置一个Apache伪静态,针对链接https://www.kaoersi.com/ask/?att=1000002%3A333,不允许其后面携带参数
时间: 2023-02-06 22:20:53 浏览: 56
可以使用 Apache 的 mod_rewrite 模块来设置伪静态。首先,需要确保 Apache 已经安装了 mod_rewrite 模块,如果没有,可以在 Apache 配置文件中加入以下行:
```
LoadModule rewrite_module modules/mod_rewrite.so
```
然后,在 Apache 的配置文件中加入以下内容,即可禁止后面携带参数:
```
RewriteEngine On
RewriteRule ^ask/att=1000002:333$ /ask/ [L]
```
如果你希望在更高级别的目录中使用伪静态,例如在网站根目录下,你可以在 .htaccess 文件中加入以上内容。
需要注意的是,如果你使用了这种方式禁止了后面携带参数,那么在访问 https://www.kaoersi.com/ask/att=1000002:333?other_param=123 时会出现 404 错误。如果你希望允许访问带有参数的 URL,但是只是不希望在 URL 中显示参数,可以使用以下方式:
```
RewriteEngine On
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^ask/att=1000002:333$ /ask/ [L]
```
这样,https://www.kaoersi.com/ask/att=1000002:333?other_param=123 将会被重写为 https://www.kaoersi.com/ask/,并且参数 other_param=123 仍然可以被服务器正常获取。