S
S
Serge Tkach2017-04-11 16:07:38
Regular Expressions
Serge Tkach, 2017-04-11 16:07:38

How to write the following rule in .htaccess?

There is a rule (found on the Internet):

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]

It should redirect pages without a trailing slash to pages with a trailing slash. It does just that. But the following bug occurs:
When opening the main page, it says that the page was not found
+
The site has pages like sitename.com/product-url.html
How to write a regular expression that would mean:
"If the string is longer than 1 character and it does not end to .html and doesn't end with /"
Thanks in advance to whoever can help! )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-04-11
@SergeTkach

I wrote in detail here https://klondike-studio.ru/standarts/standartnyy-h...
In general, the slash should be semantically and redirects should go to the slash.
In short, I painted everything here, all you need to do is turn it the other way around.
But each line is commented.
Just delete what you don't need.
put all this before activating the CNC core

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question