Home > Net >  htaccess - Set all EN pages to statuscode 410
htaccess - Set all EN pages to statuscode 410

Time:03-01

I'm trying to set all EN pages of a website to the statuscode 410. The URLs look like this:

https://example.com/en/terms-and-conditions/
https://example.com/en/sitemap/
https://example.com/en/category/page-1/
https://example.com/en/category/page-2/
https://example.com/en/category/page-3/subpage-1/

I tried different things, but none worked:

RewriteEngine On
RewriteRule ^/en(/.*)?$  - [G,NC]

this also didn't work:

RewriteEngine On
RewriteRule ^/en(.*)$ - [NC,R=410,L]

What am I doing wrong?

CodePudding user response:

When rewrite rules are used in .htaccess the URL path doesn't start with / because that is the current "base" for the rewrite rules. This is different that when rewrite rules are used in Apache's .conf files where the path does start with /.

I recommend writing rules that can be used in either place by making the starting slash optional. You just need to add a ? after the starting slash:

RewriteEngine On
RewriteRule ^/?en(/.*)?$  - [G,NC]
  • Related