.htacces redirect with special signs - .htaccess

Need help ;)
How to redirect this link?
mydomain.com/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa
Tested with:
RewriteCond %{QUERY_STRING} ^(.+&)?selbständige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
RewriteCond %{QUERY_STRING} ^(.+&)selbst%E4ndige?catid=141(&.+)?$
RewriteRule ^/$ http://test.com? [R=301,L]
redirect 301 "/selbständige?catid=141&id=141:kredit-für-selbstständige-ohne-schufa" http://test.com
...and so on.
No normal workflow works.

Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /selbst.+ndige\?catid=141&id=141:kredit-f.+r-selbstst.+ndige-ohne-schufa [NC]
RewriteRule ^ http://test.com? [L,R]
I used .+ to match against special chars in the uri.

Related

How can I exclude a request URI from redirection?

I want to redirect all page requests to another domain, but exclude some request URI which I want to redirect separately. So I have tried something like this:
RewriteCond %{REQUEST_URI} !^/index.php?id=132$ [NC,OR]
RewriteCond %{REQUEST_URI} !^/index.php?id=133$ [NC]
RewriteRule .* https://new-domain.com/? [R=301,L]
Redirect 301 /index.php?id=132 https://new-domain.com/example
Redirect 301 /index.php?id=133 https://new-domain.com/example2
But this is not working, can someone tell me what is wrong?
%{REQUEST_URI} variable or Redirect directive doesn't match query string.
You can use it like this with a better regex:
RewriteCond %{THE_REQUEST} !/index\.php\?id=13[23][&\s] [NC]
RewriteRule ^ https://new-domain.com/? [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\?id=132[&\s] [NC]
RewriteRule ^ https://new-domain.com/example? [L,R=301]
RewriteCond %{THE_REQUEST} /index\.php\?id=133[&\s] [NC]
RewriteRule ^ https://new-domain.com/example2? [L,R=301]
Also note use of ? in target URL to discard previous query string.

htaccess using RewriteRule and RewriteCond to redirect specific url

I have to redirect (301) from
http://domain/index.php to
http://domain/
I've done it with following rules:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
Ok. it works, BUT I do NOT want to allow redirect from urls like:
http://domain/asd/index.php
I've tried to change condition like:
RewriteCond %{THE_REQUEST} ^/index.php
RewriteCond %{THE_REQUEST} ^/index.php
but no success.
So, how to redirect ONLY from http://domain/index.php to http://domain/
ps: I do not want to use REDIRECT command
Try this:
RewriteRule ^index.php$ / [R=301,L]
You can use the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ / [L,R]

RewriteCond %{QUERY_STRING} ^page=3$.How to work only page=3? I do not want to redirect page=33

I want to redirect only /?page=3 to /.
/?page=33 is not redirect.
The following code also redirects /?page=33
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=3$
RewriteRule / [R=301,L]
You can use:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page=3$
RewriteRule ^ /? [R=301,L]
With ? to prevent the automatic addition of ?page=3
Try it like this, clear your browser cache first after that if it works change R=302 to 301
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=3
RewriteRule ^ / [R=302,L]

301 Redirect for URLs with % percentage mark on htacess

I neee to redirect
http://www.example.com.au/recipes/recipe.aspx?name=91-Sunflower%20Crackers
to https://www.example.com.au/recipes/
I followed so many posts but this is not redirecting at all.
This is my code
RewriteCond %{QUERY_STRING} ^name=91-Sunflower%20Crackers$
RewriteRule ^/recipes/recipe\.aspx?$ /recipes/? [NE,L,R]
What is the error here ?
This rule should work:
RewriteCond %{QUERY_STRING} "^name=91-Sunflower(\s|%20)Crackers$" [NC]
RewriteRule ^recipes/recipe\.aspx?$ /recipes/? [NC,L,R]
No leading slash in RewriteRule and use (\s|%20) in RewriteCond to match a whitespace.

RewriteRule at htaccess wrong redirect

ive this rules at htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
issue happend when redirect warcraft its redirect to
http://www.site.com/home/site/public_html/www.site.com/forumdisplay.php?f=480
any tip ?
I suppose you want to redirect it to http://www.site.com/forumdisplay.php?f=480
If so put it in your .htaccess file:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ http://www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
You must provide the full URL including protocol in your rule, in this case http://www.site.com/.....

Resources