V
V
vatrikovsky2014-03-04 12:48:03
Apache HTTP Server
vatrikovsky, 2014-03-04 12:48:03

Why doesn't the regular expression for mod_rewrite work in .htaccess?

There are some pages with addresses like /dir1/dir2/page_name_123.html, they should be redirected using mod_rewrite to
/dir1/dir2/page_name.html having the extension "html".
The code turned out offhand like this (cut out irrelevant):

# ...
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# ...

RewriteCond %{REQUEST_URI} ^/dir1/dir2/(.+)_[0-9]{1,3}\.html$
RewriteRule /dir1/dir2/(.+)_[0-9]{1,3}\.html$ http://sitename.ru/dir1/dir2/$1.html [L,R=301]

Help me figure out what's wrong? It does not complain about the syntax, mod_rewrite is enabled and successfully fulfills the rest of the requests, but this particular one does not give anything.
I apologize in advance if the mistake is amateurish, but I'm stupid.
PS In the load - should (.+) be replaced with something like (^/)+ to cut off subdirectories? In fact, they are not in the structure, but you never know, they suddenly appear.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kompi, 2014-03-04
@vatrikovsky

It worked for me without the 1st slash in the rewriterule:
RewriteRule dir1/dir2/(.+)_[0-9]{1,3}\.html$

V
vatrikovsky, 2014-03-04
@vatrikovsky

Thanks, it worked!
However, what is the reason for this, I did not understand. I will dig the documentation further, most importantly, the urgent task is solved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question