我想将所有请求重写为index.php?r =,以便使/ sth变为/index.php?r=sth
我已经应用了这个有效的规则:
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^.*\.(jpg|css|js|gif|png|pdf|php)$ [NC]
RewriteRule ^(.+)$ index.php?r=$1 [L]
但是我也想有这样的重定向
Redirect 301 /sth /sth-new
发生的事情是它可以工作,但URL变为:
/sth-new?r=sth
您有什么解决方案-关于为什么会这样的建议吗?如何实现全局规则并进行简单的重定向?
您可以这样做:
RewriteRule ^sth/?$ /sth-new? [L,R=301]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !\.(jpg|css|js|gif|png|pdf|php)$ [NC]
RewriteRule ^(.+)$ index.php?r=$1 [L]
在内部重写规则之前,应保留外部重定向规则。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句