简体   繁体   English

简单的htaccess重写规则错误404

[英]Simple htaccess rewrite rule error 404

I'm trying to set a simple htaccess rule, but is not working. 我正在尝试设置一个简单的htaccess规则,但是不起作用。
I think the problem is with the ? 我认为问题出在? and = characters? =字符?

The code is: 代码是:

Options +FollowSymLinks 
ErrorDocument 404 /php/404redirect.php
RewriteEngine on
RewriteRule ^productos.php?id=([0-9]+)$ /?view=productos&id=$1 [L,NE,B,QSA]

This always give me error 404. 这总是给我错误404。

What I want is redirect all requests from: 我想要的是重定向来自的所有请求:
www.example.com/productos.php?id=X
to
www.example.com/?view=productos&id=X

Querystring is not part of match in RewriteRule directive, to redirect query strings, you need to use RewriteCond one of the following options : Querystring不是RewriteRule指令中match的一部分,要重定向查询字符串,您需要使用RewriteCond以下选项之一:

option 1 选项1

RewriteEngine on

RewriteCond %{THE_REQUEST} /product\.php\?id=([^&\s] [NC]
RewriteRule ^ /?view-product&id=%1? [NC,L,R]

option 2 选项2

RewriteEngine on

RewriteCond %{QUERY_STRING} ^id=([^&]+)$ [NC]
RewriteRule ^product\.php$ /?view-product&id=%1? [NC,L,R]

We use an empty question mark ? 我们使用一个空的问号 at the end of the target url to discard the old query strings, otherwise these query strings get appened to the target url by default. 在目标网址的末尾丢弃旧的查询字符串,否则默认情况下,这些查询字符串会附加到目标网址。

Change the R to R=301 if you want to make the redirection permanent. 如果你想重定向永久更改RR = 301。

RewriteRule ^productos.php /?view=productos [L,NE,B,QSA]

或者如果您想重定向

RewriteRule ^productos.php /?view=productos [L,NE,B,QSA,R=301]

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

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