.htaccess for wordpress network @wpengine - adds trailing slash to 404 pages


/ Published in: Apache

In my WP networks, I use a custom 404 page and plugin to answer calls asking for user information from a custom api. The API requires a URL format like this:
domain.com/username/
However, users don't ever type a trailing slash, nor should they, so this allows for a trailing slash anywhere but inside admin, except where it is needed in admin...


Copy this code and paste it in your HTML
  1. # BEGIN WordPress
  2. RewriteEngine On
  3. RewriteBase /
  4. RewriteRule ^index\.php$ - [L]
  5.  
  6. # uploaded files
  7. RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
  8.  
  9. # add a trailing slash to /wp-admin
  10. RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
  11.  
  12. RewriteCond %{REQUEST_FILENAME} -f [OR]
  13. RewriteCond %{REQUEST_FILENAME} -d
  14. RewriteRule ^ - [L]
  15.  
  16. RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
  17. RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
  18.  
  19. #So far, we've not found a real file, folder or virtual folder with this URL, add a slash and call 404 so my API can fulfil the request.
  20. RewriteCond %{REQUEST_FILENAME} !-f
  21. RewriteCond %{REQUEST_URI} !(.*)/$
  22. RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
  23.  
  24. RewriteRule . index.php [L]
  25.  
  26.  
  27.  
  28. # END WordPress

URL: http://twitter.com/lchoate

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.