Posted By

lucasoptura on 12/09/12


Tagged

php wordpress htaccess mod-rewrite mu


Versions (?)

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


 / Published in: Apache
 

URL: http://twitter.com/lchoate

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...

  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

Report this snippet  

You need to login to post a comment.