1

My wordpress use custom permalinks url with rules /%postname%.html

And Htaccess rules

# This file was updated by Duplicator Pro on 2021-11-02 05:53:04.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

So my post url looks like this (with amp plugin)

https://www.host.com/post.html <--- original url

https://www.host.com/post.html/amp <--- amp url

https://wwww.host.com/post.html/amp/ <--- amp url

https://wwww.host.com/post.html?amp <--- amp url

https://wwww.host.com/post.html?amp=1 <--- amp url

I have disabled amp plugin recently , this leave me with thousand not found url from previous amp url ..and i used solution provided on this answer https://stackoverflow.com/questions/41733666/htaccess-to-remove-amp-from-the-end-of-a-url/46231142

so my htaccess looks like this

# This file was updated by Duplicator Pro on 2021-11-02 05:53:04.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/amp(.*)$
RewriteRule ^ %1/ [R=301,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

But then i moved from shared hosting to vps (centos 7) ..using the same rules, now it add additional slash in url https://www.host.com/post.html/ where it should be https://www.host.com/post.html

Request 
> GET /post.html/amp/ HTTP/1.1
> Host: www.host.com
> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246
Response 
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 04 Nov 2021 07:43:16 GMT
< Content-Type: text/html; charset=iso-8859-1
< Content-Length: 274
< Connection: keep-alive
< location: https://www.host.com/post.html/
< cache-control: max-age=0
< expires: Thu, 04 Nov 2021 07:43:16 GMT
< CF-Cache-Status: DYNAMIC
< Server: cloudflare

my apology if i post to long question, but i need help to redirect /amp /amp/ ?amp ?amp=1 ?amp=0 to original non amp url

Thank you

4
  • This question would be better asked on the Webmasters stack: webmasters.stackexchange.com as it doesn't really have anything to do with WordPress development.
    – MrWhite
    Nov 4, 2021 at 10:22
  • You've introduced a wwww subdomain in your 3rd, 4th and 5th example URLs - in this a typo? Although if it is a typo then your 2nd and 3rd example URLs are the same - should one perhaps be missing the trailing slash?
    – MrWhite
    Nov 4, 2021 at 10:25
  • "But then i moved from shared hosting to vps" - Are you implying this all worked as intended at the shared host?
    – MrWhite
    Nov 4, 2021 at 10:38
  • ah yes there's typo on 3rd and 4th url my bad , and regarding migration, no and yes ...htaccess rule above doesn't works on ?amp , its only works on /amp/ but i've installed plugin to handle ?amp
    – Yudi Anto
    Nov 4, 2021 at 13:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.