A
A
Alexander2019-10-19 17:36:25
htaccess
Alexander, 2019-10-19 17:36:25

I don't understand why htaccess is not working?

Made a small .htaccess file,
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^[^www\.].*$ [NC]
RewriteRule ^/?([a-z0-9\-]+)/?$ /index.php?item=$1 [NC,L]
Makes a redirect from www to without www and sends everything after the domain to index.php?item=
But there is one caveat, a dot can still be indicated there, I do it like this ^/?([a-z0-9\-\.] +)/?$
But the server gives a 500 error
What could be wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2019-10-19
Fedosienko @Alexander Fedosienko

When adding a dot - index.php also falls under the rule and the redirect is endless.
To avoid this, they usually add a condition that prohibits the execution of the rule if the requested file actually exists:
RewriteCond %{REQUEST_FILENAME} !-f

D
Dimonchik, 2019-10-19
@dimonchik2013

logs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question