简体   繁体   English

.htaccess 301使用php获取查询重定向(旧URL到新更新)

[英].htaccess 301 Redirect (old url to new update) with php get query

I am trying to redirect a few old URLs to new ones using htaccess, which rewrites a GET query in my PHP file to clean URLs: 我正在尝试使用htaccess将一些旧URL重定向到新的URL,htaccess在我的PHP文件中重写GET查询以清理URL:

Options +FollowSymLinks
RewriteEngine on
RedirectMatch 301 /photo/old-photo /photo/new-photo    
RewriteRule ^photo/(.*)/?$ tpl-photo.php?slug=$1
RewriteRule ^photo/(.*)?$ tpl-photo.php?slug=$1

This outputs my clean URLs correctly like so: 这样就可以正确输出我的干净URL:

http://website.com/photo/one-beautiful-photo

However, when I try to redirect my old URLs to new URLs, it somehow messes up the URL: 但是,当我尝试将旧网址重定向到新网址时,它会以某种方式弄乱网址:

http://website.com/photo/new-photo?slug=old-photo

How can I correct this so that I get a proper clean new URL: 我该如何纠正这个问题,以便获得一个合适的干净的新网址:

http://website.com/photo/new-photo

Don't mix mod_rewrite and mod_rewrite rules and keep only mod_rewrite rules like this: 不要混用mod_rewritemod_rewrite规则,只保留mod_rewrite规则,如下所示:

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^photo/old-photo/?$ /photo/new-photo [NC,L,R=301]
RewriteRule ^photo/([^/]+)/?$ tpl-photo.php?slug=$1 [L,QSA,NC]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM