A
A
Anton Kunakovsky2020-04-23 15:59:50
htaccess
Anton Kunakovsky, 2020-04-23 15:59:50

How to redirect to the root of an Apache site?

There was a problem redirecting from a page like localhost/CMS to localhost
Here's the code: Works, but only if there is no "?" localhost/CMS/?result=post&s=post redirects to localhost/?result=post&s=post and the rule shouldn't fire. Tried via Rewrite: (all htaccess code)
Redirectmatch 301 ^(.*)CMS/?$ $1


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CMS/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !CMS/?$ #надеюсь, исключил из следующего правила
RewriteRule .* /CMS/index.php [L]
</IfModule>

Redirectmatch 301 ^(.*)blog/*$ $1blog/home
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule .*CMS/?$ /  [R=301,L]
</IfModule>

Works only virtually https://htaccess.madewithlove.be?share=834e5846-da...
Where is my logic wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-04-23
@qnak

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{THE_REQUEST} "^GET /CMS/ "
RewriteRule ^ / [R=301,L]
</IfModule>


<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /CMS/index.php [L]
</IfModule>

V
Viktor Taran, 2020-04-23
@shambler81

The get parameter is not part of the url, and therefore RewriteRule does not see it at all.
To select it, use RewriteCond
In your case, you just need to delete it.
Make it easy
Redirectmatch 301 ^(.+)CMS/?$ /$1?
where the question at the end will delete the get parameter,
or, like this, tweak the regular expression itself, because in you in the task is clearly not all written. Also don't forget about Linux case sensitivity and add flag NC
RewriteRule ^cms/aaaa$ /? [L,R=301,NC]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question