Redirect urls with spaces via htaccess - .htaccess

I want to redirect the following url :
/wp-content/uploads/images/TOWER/Dark%20Tower%20Official%20Art.html
I tried the following in the htaccess file :
RedirectMatch "/wp-content/uploads/images/TOWER/Dark\ Tower \ Official \ Art.html" url [L,R=301]
But it doesnt work as it gives me a 500 error.
Any idea of how I could fix this?
Thanks !

Change every %20 to \s (RegEx whitespace character)
RewriteEngine On
RewriteRule ^wp\-content\/uploads\/images\/tower\/dark\stower\sofficial\sart\.html$ /new-link [R=301,NC,L]

Related

301 rewrite will not redirect

Hi looking for some help, i have a product link
iphone%20-5c-replacement-button
i have removed the blank space and i am trying to set up a "301 rewriterule" to the new page.
i tried this
RewriteRule ^iphone%20-5c-replacement-button$ /iphone-5c-replacement-button [R=301,L]
But this did not work, so i tried this way
Redirect 301 "/iphone -5c-replacement-button" http://www.mysite.co.uk/iphone-5c-replacement-button
i also tried
Redirect 301 "/iphone -5c-replacement-button" "http://www.mysite.co.uk/iphone-5c-replacement-button"
can anyone please help with this problem
You can match the space %20 using \s char in RewriteRule
RewriteRule ^iphone\s-5c-replacement-button$ /iphone-5c-replacement-button [R=301,L]

htacces to redirect to another page if the url contains 'manager'

I am trying to redirect the user based on the url they are using. Basically if the url contains something like www.my-domain.com/manager/ then redirect to www.my-domain.com/admin/Login.php .
If the url has "manager" with a trailing slash or without a trailing slash then redirect it to www.my-domain.com/admin/Login.php.
RewriteCond %{HTTP_HOST} ^manager/$
RewriteRule .* admintti/Login.php
The above code I am trying but its of no use.
Any help would be greatly appreciated. Thanks
You don't really need mod_rewrite for this.
Try this:
RedirectMatch ^/manager(.+) /admintti/Login.php
RewriteRule .*?manager.* admintti/Login.php
You're matching against the HTTP_HOST, which doesn't contain any path info. you want to match where the .* is:
RewriteRule .*manager.* /admin/Login.php [L]

Rewrite doesn't work without trailing slash

I have problems getting an URL to work WITHOUT entering trailing slash.
It's:
www.domain.com/shop/buy/products/show/range/
.htaccess Rewrite Rule is:
RewriteRule ^shop/buy/([A-Za-z0-9]+)/show/([A-Za-z0-9\-\,]+)/?$ _shop/products.php?trg=${productmap:$1}&range=$2 [L]
It works with trailing slash (which I don't want in the URL) but not without. I should also add that if I was to remove '/show/' from the URL (which I can't do though), it works without trailing slash, or if 'range' contains a dash '-', as in 'new-product', it also works.
However, this URL works with or without trailing slash:
www.domain.com/shop/buy/products/show/range/color
.htaccess Rewrite Rule for this URL is:
RewriteRule ^shop/buy/([A-Za-z0-9]+)/show/([A-Za-z0-9\-\,]+)/([A-Za-z0-9\-\,]+)/?$ _shop/products.php?trg=${productmap:$1}&range=$2&color=$3 [L]
How can I get the first URL to work without trailing slash? This might be something really obvious as I'm a recent newbie to using .htaccess but I have now spent hours staring at the code and reading forum posts about rewrites but not been able to resolve this. Thank you!
T'm not so sure, but have You try to put /? in braces: (/)?, I think this will work:
RewriteRule ^shop/buy/([A-Za-z0-9]+)/show/([A-Za-z0-9\-\,]+)([/]?)$ _shop/products.php?trg=${productmap:$1}&range=$2 [L]
You Can Test This Code
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^shop/buy/(.*?)/show/(.*)/(.*)$ _shop/products.php?trg=$1&range=$2&color=$3 [S,L,QSA]
RewriteRule ^shop/buy/(.*?)/show/(.*)$ _shop/products.php?trg=$1&range=$2 [S,L,QSA]
sample:
www.domain.com/shop/buy/products/show/range/
www.domain.com/shop/buy/products/show/range
redirect to:
www.domain.com/_shop/products.php?trg=products&range=range
and:
www.domain.com/shop/buy/products/show/range/color
www.domain.com/shop/buy/products/show/range/color/
redirect to:
www.domain.com/_shop/products.php?trg=products&range=range&color=color
one Another way is you Can Use Only This code
RewriteRule ^shop/buy/(.*?)/show/(.*)$ _shop/products.php?trg=$1&range=$2 [L,QSA]
after That split range in php By
list($range,$coler)=explode("/",$_GET['range']);
It is work too.

redirect with or without slash with mod_rewrite

I use mod_rewrite to redirect the request to a PHP file :
RewriteRule gallery$ mod.php?m=gallery
everything is ok when I call the url in this format : http://localhost/project/gallery but when I call the http://localhost/project/gallery/ I get the page not fount error.
What should I do to solve this problem? should I enter a duplicate line with / ?
Your rule should be like this:
RewriteRule gallery/?$ mod.php?m=gallery [L,QSA,NC]

.htaccess program slash getting added to url

I am trying to write the following .htaccess
RewriteRule ^follower/([A-Za-z0-9-]+)/?$ follower.php?username=$1 [NC,L]
But it executing like follower.php/?username=example , So my page CSS getting problem .. Total layout getting disturbed !
Any solution to this problem ?
Thanks in advance
Escape your slashes
RewriteRule ^follower\/([A-Za-z0-9-]+)\/?$ follower.php?username=$1 [NC,L]

Resources