如果在其网址中发生更改,则重定向网页

时间:2015-04-02 06:41:59

标签: php .htaccess redirect

我的网页是带有网址参数的日期:

/artandculture/details.php?articleid=28208&parentid=1&catid=166

我希望如果用户更改了网址,那么它会重定向到主网址,例如网址中的任何更改都会重定向到:

/artandculture/details.php?articleid=28208&parentid=1&catid=166

是否有.htaccess的解决方案?

1 个答案:

答案 0 :(得分:0)

确认后,请使用htaccess

尝试此解决方案
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/artandculture/details\.php
RewriteCond %{QUERY_STRING} !^articleid=[0-9]+&parentid=[0-9]+&catid=[0-9]+$
RewriteRule .* /artandculture/details.php?articleid=28208&parentid=1&catid=166 [L,NC,R=307]

RewriteCond将检查是否已请求uri是您的相关页面,然后将执行。接下来RewriteCond将检查GET参数是否不存在或者格式错误,然后将URL更改为主PAGE。

从上一个规则中删除,R=307不会重定向(更改浏览器中的地址),这只会显示包含用户更改URL的主页面。