M
M
Maxim Sofronov2016-08-12 00:14:41
Apache HTTP Server
Maxim Sofronov, 2016-08-12 00:14:41

How to exclude from .htaccess redirect pages ending with #hashtag with a space (need help with regex)?

The .htaccess has a rule:

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

That is, if the page ends without a slash, then it is redirected to a page with a slash, for example:
site.ru/about → site.ru/about /
At the same time, if the page ends with .html, then the redirect does not occur.
So far everything is correct.
As soon as I call such a page (yes, there is a space and a hashtag): site.ru/about/ #page
then a redirect occurs to site.ru/about/ %20/ #page The
trouble is that after the space sign (%20) a slash is placed. How to make it so that it is not set and the redirect does not occur, but the site.ru/about/ %20 #page page simply opens?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Sofronov, 2016-08-12
@maxsof

Decided like this:

RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteCond %{REQUEST_URI} /+[^\ ]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question