简体   繁体   English

.htaccess RewriteRule重定向

[英].htaccess RewriteRule redirect

i need help redirecting this two links to one link: 我需要帮助将这两个链接重定向到一个链接:

Link #1: http://www.domain.com/index.php?til=d_news&id_new=1
Link #2: http://www.domain.com/new_folder/?til=d_news&id_new=1

need to redirect to: 需要重定向到:

http://www.domain.com/news/news.html

i tried using this code: 我尝试使用此代码:

RewriteCond %{QUERY_STRING} ^til=d_news
RewriteRule ^(.*)$ http://%{HTTP_HOST}/news/news.html? [R=301,L]

but it only redirects the first link and not the second. 但它只重定向第一个链接而不是第二个链接。

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory: 通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在DOCUMENT_ROOT目录下的.htaccess

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1 [NC]
RewriteRule ^ /news/news.html? [R=301,L]

In the htaccess file in your document root, add: 在文档根目录中的htaccess文件中,添加:

 RewriteEngine On
 RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1 
 RewriteRule ^index.php$ /news/news.html? [L,R=301]

 RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
 RewriteRule ^new_folder/?$ /news/news.html? [L,R=301]

In your second link there is no destination page: 在您的第二个链接中没有目标页面:

http://www.domain.com/new_folder/?til=d_news&id_new=1

should be something like: 应该是这样的:

http://www.domain.com/new_folder/page.php?til=d_news&id_new=1

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

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