#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1

    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
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,895
    Rep Power
    9646
    What are you trying to redirect to? The homepage? How does it "not work"?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    Yes Homepage https://www.mysite.it, but it does not redirect....
  6. #4
  7. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,895
    Rep Power
    9646
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    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>
  10. #6
  11. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,895
    Rep Power
    9646
    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.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    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?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    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?
  16. #9
  17. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,895
    Rep Power
    9646
    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?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    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.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    Hello
    I tried to make test here https://htaccess.mwl.be/ but give me error in RewriteRule. You can see it.
  22. #12
  23. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,895
    Rep Power
    9646
    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...
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2018
    Posts
    65
    Rep Power
    1
    YOU ARE THE BEST.... I understand what you mean... now work!
    Thank you very much...

IMN logo majestic logo threadwatch logo seochat tools logo