3

I want to have only URLs with trailing slash on my website. At the moment I have only URLs without trailing slash. How I have to modify my htaccess?

Here it is:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)/[0-9]+$ %{REQUEST_URI}/ [QSA,L,R=301]
RewriteRule ^unternehmen-2-2/?$ /unternehmen [L,R=301,NC]
RewriteRule ^expose/(.*)/$ content/index.php?content=expose&query=$1 [L,QSA]

</IfModule>


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

# END WordPress

I hope somebody can help me.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
tom84
  • 371
  • 1
  • 3
  • 15

1 Answers1

0

You can use these rules above default wordpress .htaccess:

RewriteEngine On
RewriteBase /

# add trailing slash too all URLs
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteRule ^unternehmen-2-2/?$ /unternehmen/ [L,R=301,NC]

RewriteRule ^expose/(.*)/$ content/index.php?content=expose&query=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks for your answer...when i try your solution nothing happens... i still have paths without trailing slashes. The internal paths show to urls with trailing trashes and than it redirects to "no trailing trashes"... – tom84 Jul 15 '16 at 08:30
  • Keep my `add trailing slash` as your very first rule and then test in Chrome dev tool with caching disabled and check in Networking tab what are 301/302 redirect URLs you get. – anubhava Jul 15 '16 at 09:08
  • i get no redirect. All sites get a 200. Now i have your code in my htaccess if you want to check... – tom84 Jul 15 '16 at 11:08
  • I cannot check without knowing your website URL. Can you show your latest full .htaccess in question and also make sure in WP permalink settings you have a trailing slash `/` as well – anubhava Jul 15 '16 at 14:07