0

I'm using WordPress and I have a URL like this:

domain.com/my-pages/The+Title/go/

I want the 'go' removed, and my-pages changed to books, like this:

domain.com/books/The+Title

without causing a 404 error.

It isn't possible via permalinks as I'm using a custom plugin.

I've tried this in .htaccess but it doesn't work:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^my-pages/([^\.]+)/go/$ books/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

Any ideas?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Sam
  • 37
  • 1
  • 9

1 Answers1

1

IIRC when in .htaccess the path starts with a slash ("/"), so as you anchor the regular expression at the beginning of the string ("^" symbol):

RewriteRule ^/my-pages/([^\.]+)/go/$ books/$1 [L]
             ^
              `-- missing in your case

You can control that with RewriteBaseApache DOCs, see as well:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836