A
A
Alexey2015-11-21 03:27:41
Apache HTTP Server
Alexey, 2015-11-21 03:27:41

How to make redirects for every rewrite?

I have a lot of rewrites in htaccess, how can I make it so that each one has a redirect to a link with a slash at the end, if there is no slash at the end of the link?
Example:

RewriteRule ^([0-9]+)/$ /index.php?page=$1 
RewriteRule ^news/$ /index.php?mode=news
RewriteRule ^articles/$ /index.php?mode=articles
RewriteRule ^posts/feedback/$ /index.php?mode=posts

Is it really necessary to write something like this before each?
RewriteRule ^([0-9]+)$ /$1/
RewriteRule ^([0-9]+)/$ /index.php?page=$1
RewriteRule ^news$ /news/
RewriteRule ^news/$ /index.php?mode=news
RewriteRule ^articles$ /articles/
RewriteRule ^articles/$ /index.php?mode=articles
RewriteRule ^posts/feedback$ /posts/feedback/
RewriteRule ^posts/feedback/$ /index.php?mode=posts

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey S., 2015-11-21
@dzheka3d

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]

Well, then your rewrites:
RewriteRule news/$ /tmp/
RewriteRule forum/$ /tmp/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question