Answer the question
In order to leave comments, you need to log in
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>
Answer the question
In order to leave comments, you need to log in
<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>
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$ /?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question