March 30th, 2018, 12:08 PM
-
redirect /post?id=
Hello
I have 400 error 404 of this type. After id, code alphanumeric change...
I want redirect this error in homepage https://www.mysite.it
I'm trying to put code in htaccess for redirect 301 in WordPress
https://www.mysite.it/post?id=1c09cc...1-23b46515143e
This is solution of my code but don't work, what i wrong?
Can you help me?
Code:
RewriteCond %{QUERY_STRING} id=([0-9a-zA-Z_-]) [NC]
RewriteRule ^/post?$ /$1/ [L,NC,NE,R=301,QSD]
Thank you very much
Fabry
March 30th, 2018, 09:29 PM
-
What are you trying to redirect to? The homepage? How does it "not work"?
March 31st, 2018, 03:07 AM
-
March 31st, 2018, 10:02 AM
-
Do you remember what question marks do? They make the previous thing optional. You're using a question mark in there that does not belong. But it won't cause your problem.
Do you remember what $1 means? It's the first capturing group from the RewriteRule. You don't have any capturing groups. I don't think mod_rewrite will skip the rule because $1 doesn't exist, but it could. Still it shouldn't be there.
If removing $1 doesn't make it work then post your full .htaccess. There may be some conflicting rules.
March 31st, 2018, 01:41 PM
-
I'm doing so but don't redirect
Code:
RewriteCond %{QUERY_STRING} id=([A-Za-z0-9_]+)$ [NC]
RewriteRule ^/post?$ / [L,NC,NE,R=301,QSD]
This is my htaccess
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase //
RewriteRule ^[0-9]+\..+\.cpaneldcv$ - [L]
RewriteRule ^\.well-known/acme-challenge/[0-9a-zA-Z_-]+$ - [L]
RewriteRule ^\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ - [L]
RewriteCond %{QUERY_STRING} id=([A-Za-z0-9_]+)$ [NC]
RewriteRule ^/post?$ / [L,NC,NE,R=301,QSD]
RewriteCond %{QUERY_STRING} page=([^&]+) [NC]
RewriteRule ^/?$ /$1/ [L,NC,NE,R=301,QSD]
RewriteRule ^default/?$ /$1/ [R=301,L,QSD]
RewriteCond %{QUERY_STRING} name=([^&]+) [NC]
RewriteRule ^/?$ /$1/ [L,NC,NE,R=301,QSD]
RewriteCond %{QUERY_STRING} picture=([^&]+) [NC]
RewriteRule ^image\.axd$ //wp-content/uploads/upload%1? [L,NC,NE,R=301]
RewriteRule ^\d{4}/\d\d/(default) //$1 [R=301,L]
RewriteRule ^images/(.+?)(?:\.jpgx)?$ //wp-content/uploads/upload/$1 [L,NC,NE,R=301]
RewriteRule ^(.*).aspx$ https://www.mysite.it/$1 [R=301,L]
RewriteRule ^.*post/\d{4}/\d{2}/\d{2}/(.*) //$1/ [R=301,L]
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*) //$1/ [R=301,L]
RewriteRule ^[Bb]log[Ee]ngine/post/(.*) //$1/ [R=301,L]
RewriteRule ^post/(.*) //$1/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . //index.php [L]
</IfModule>
April 1st, 2018, 12:36 AM
-
Your current regex isn't including hyphens.
And that question mark still shouldn't be there. Get rid of it.
And you have a few places where the slash is doubled up. Don't do that.
April 2nd, 2018, 12:14 PM
-
I did that but don't redirect
Code:
RewriteCond %{QUERY_STRING} id=([0-9a-zA-Z_-]+)$ [NC]
RewriteRule ^/post$ / [L,NC,NE,R=301,QSD]
And you have a few places where the slash is doubled up in which line of code? For example?
April 7th, 2018, 04:34 PM
-
I removed all the other redirects and left only this, no conflict .. it does not work
Code:
RewriteCond %{QUERY_STRING} id=([0-9a-zA-Z_-]+)$ [NC]
RewriteRule ^/post$ / [L,NC,NE,R=301,QSD]
What could be the problem?
April 7th, 2018, 06:28 PM
-
Originally Posted by fabry19dice
And you have a few places where the slash is doubled up in which line of code? For example?
"Doubled up" means that there are two things repeated. "Slash is doubled up" means there are two slashes repeated. Look at your .htaccess (or at least what you posted) and see where there are places that have two slashes repeated.
Originally Posted by fabry19dice
I removed all the other redirects and left only this, no conflict .. it does not work
Compare this RewriteRule
Code:
RewriteRule ^/post$ / [L,NC,NE,R=301,QSD]
with some of the others that are working:
Code:
RewriteRule ^[0-9]+\..+\.cpaneldcv$ - [L]
RewriteRule ^\.well-known/acme-challenge/[0-9a-zA-Z_-]+$ - [L]
RewriteRule ^\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ - [L]
RewriteRule ^default/?$ /$1/ [R=301,L,QSD]
RewriteRule ^image\.axd$ //wp-content/uploads/upload%1? [L,NC,NE,R=301]
RewriteRule ^\d{4}/\d\d/(default) //$1 [R=301,L]
RewriteRule ^images/(.+?)(?:\.jpgx)?$ //wp-content/uploads/upload/$1 [L,NC,NE,R=301]
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*) //$1/ [R=301,L]
RewriteRule ^[Bb]log[Ee]ngine/post/(.*) //$1/ [R=301,L]
RewriteRule ^post/(.*) //$1/ [R=301,L]
RewriteRule ^index\.php$ - [L]
Especially this one:
Code:
RewriteRule ^post/(.*) //$1/ [R=301,L]
Can you see anything about this new RewriteRule that is different from the others?
April 9th, 2018, 06:10 AM
-
this is rows of code with slashed is doubled up... I can put only one slash?
Code:
RewriteRule ^image\.axd$ //wp-content/uploads/upload%1? [L,NC,NE,R=301]
RewriteRule ^\d{4}/\d\d/(default) //$1 [R=301,L]
RewriteRule ^images/(.+?)(?:\.jpgx)?$ //wp-content/uploads/upload/$1 [L,NC,NE,R=301]
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*) //$1/ [R=301,L]
RewriteRule ^[Bb]log[Ee]ngine/post/(.*) //$1/ [R=301,L]
RewriteRule ^post/(.*) //$1/ [R=301,L]
but why programmer that work in this file put a double slash? What is the difference with one slash?
- This RewriteRule is used for this redirection
Code:
RewriteRule ^post/(.*) //$1/ [R=301,L]
Code:
from: http://www.mysite.it/post/mypost.php]
to: http://www.mysite.it/mypost.php]
- This RewriteRULE is used for this redirection
Code:
RewriteCond %{QUERY_STRING} id=([0-9a-zA-Z_-]+)$ [NC]
RewriteRule ^/post$ / [L,NC,NE,R=301,QSD]
https://www.mysite.it/post?id=f65baa...a-0098aaaaad91
are different no??
Last edited by fabry19dice; April 9th, 2018 at 06:16 AM.
April 9th, 2018, 10:21 AM
-
April 9th, 2018, 12:01 PM
-
No, actually, I can't see it.
I don't know why the person who wrote your .htaccess put two slashes in some places and not others. There's no reason to. It's not harmful but there's no reason to have them. One is fine.
Some of the rewriting also tries to use $1 when there were not any capturing groups. $1 does not exist. It will be nothing. Also not harmful, also no reason for it to be there. Also results in some doubled slashes.
What I was trying to get you to see by visually comparing the different RewriteRules was that the ones that are working do not have a leading slash and the one you're trying does have a leading slash. So...
April 9th, 2018, 04:09 PM
-
YOU ARE THE BEST.... I understand what you mean... now work!
Thank you very much...