如何301使用PHP参数将URL重定向到.htaccess中的根DIR?

时间:2021-07-16 10:38:33

I have searched how to redirect url with parameters to root dir but I can't get it to work :(

我已经搜索了如何将参数重定向到根目录,但我无法让它工作:(

This is what the .htaccess code looks like:

这就是.htaccess代码的样子:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

RewriteEngine On
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^phpnuke/modules\.php$ /? [L,R=301]

I have url such as "http://www.domain.com/phpnuke/modules.php?name=News&file=article&sid=60" and I want to redirect it to "http://www.diagonally.org/"

我有网址,如“http://www.domain.com/phpnuke/modules.php?name=News&file=article&sid=60”,我想将其重定向到“http://www.diagonally.org/”

2 个解决方案

#1


Keep redirect rule before default WP rewrite rule and match correct query string:

在默认WP重写规则之前保留重定向规则并匹配正确的查询字符串:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} name=News&file=article&sid=60
RewriteRule ^phpnuke/modules\.php$ /? [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

#2


Try some thing like this

尝试这样的事情

# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]

#1


Keep redirect rule before default WP rewrite rule and match correct query string:

在默认WP重写规则之前保留重定向规则并匹配正确的查询字符串:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} name=News&file=article&sid=60
RewriteRule ^phpnuke/modules\.php$ /? [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

#2


Try some thing like this

尝试这样的事情

# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]