P
P
pirojok_yoyo2017-09-01 15:04:19
htaccess
pirojok_yoyo, 2017-09-01 15:04:19

How to set a condition in htaccess so that if there is something in the url after the second slash, it redirects to 404?

How to set a condition in htaccess so that if there is something in the url after the second slash, it redirects to 404?
example if the url is https://toster.ru/question/here_there_is_something_

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-09-02
@shambler81

RewriteCond %{REQUEST_URI} ^question/.+ [NC]
RewriteRule . - [R=404,L,NC]

If after the question there is something to redirect to 404, but you can also redirect to a file that gives 404, then it will be 301 + 404
Well, any after the second from 1 directory.
just need to clarify whether the quantifier will work
In this case, ?/ - the first slash at the end
RewriteCond %{REQUEST_URI} ^.+?/.+ [NC]
RewriteRule . - [R=404,L,NC]

If it doesn't work then
RewriteCond %{REQUEST_URI} ^([^\/].+)\/) [NC]
RewriteRule . - [R=404,L,NC]

[^\/] - not /
these redirects will not affect urls with GET requests, but they were not in the specification

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question