301 redirect with {~`% characters in url - apache

Trying to apply a 301 redirect to this url "/Qx%40w%2C6M42VAwp3%40Rb%7B~cC4ure%60QWI9" but it's not liking it, i'm guessing because of the horrible url and all the strange characters in it, any ideas?
This is the code I currently have:
redirect 302 /Qx%40w%2C6M42VAwp3%40Rb%7B~cC4ure%60QWI9 /product-tool-case.php

You can do this with mod_rewrite as follows:
RewriteRule ^/Qx%40w%2C6M42VAwp3%40Rb%7B~cC4ure%60QWI9 /product-tool-case.php
I?f you want to continue using mod_alias as above, then you should ensure that the old url is url-decoded. So in the above example try:
redirect 302 /Qx#w,6M42VAwp3#Rb{~cC4ure`QWI9 /product-tool-case.php

Related

Redirect one path to another while preserving the URL before the matching criteria

I'm trying to redirect some path to another using .htaccess:
RedirectMatch 301 /de/path(.*) /path$1
What i really want to is to get rid of the "/de/" part (only when there is also /path following it) and redirect to /path. The rule above is working, however it redirects to the root of the domain.
How can i preserve the URL that is before /de/path and use it when redirecting to /path, i.e. :
http://example.com/some/otherdirectory/de/path to redirect to http://example.com/some/otherdirectory/path?
This is as simple as:
RedirectMatch 301 (.*)/de/path $1/path
If there is a need to also match what is after /de/path and append it to the new path:
RedirectMatch 301 (.*)/de/path(.*) $1/path$2

Redirect duplicate urls using htaccess

i need help with htaccess advanced redirect.
Like i have some pages in my blog,
URL example site.com/en/post-detail/90
User can access same page by link
site.com/en/post-detail/90/(anything after slash)
so i want to redirect all requests like
site.com/en/post-detail/90/(anything) to site.com/en/post-detail/90.
/en/ - is various, it can be Ru, pt, it, fr etc.
/90/ - is the id of post, so it is always numbers
Try :
RedirectMatch 301 ^/((en|ru|pt|it|fr)/post-detail/([0-9]+))/.+$ /$1

Rewrite language code into url if missing

I want to change an existing Magento store to add store/lang codes to the url i.e.
http://mystore/en/PRODUCTXYZ.html
http://mystore/de/PRODUCTXYZ.html
Old links to http://mystore/PRODUCTXYZ.html will now throw a 404 error.
How can I create an Apache url rewrite rule to add a language code if it is missing i.e. rewrite
http://mystore/PRODUCTXYZ.html
to
http://mystore/de/PRODUCTXYZ.html
So that old links 301 redirect to the correct product.
I have worked around this with
Redirect 301 /PRODUCTXYZ http://mystore/de/PRODUCTXYZ.html
But obviously for thousands of products this might not be practical.
You can redirect multiple Product.html urls with just 1 line of code using RedirectMatch :
RedirectMatch 302 ^/([^/.]+)\.html$ http://example.com/de/$1.html
I used 302 for testing purposes and to avoid browser's cache,
change 302 to 301 (permanent redirect) when you are sure the redirect is working.

301 Redirect A URL Pattern Using .htaccess

I want to redirect my URLs to a new pattern. For this purpose, I used 301 redirect for every single URL but that are taking a huge time and my .htaccess file is going large and large as I have thousands of URLs.
So now Someone said to me to use .htaccess to use 301 redirect or rewrite engine option. Now I am new to .htaccess to use Pattern Redirect. First of all clear me out that is this possible to use 301 redirect in patterns? If yes then Can I do pattern 301 redirect in the below URLs? I want to redirect the below pattern so can you help me?
/search/label/XXXXXXXXXX to /category/XXXXXXXXXX
/year/month/XXXXXXXXXX.html/?m=0 to /year/month/XXXXXXXXXX.html
/year/month/XXXXXXXXXX.html/?m=1 to /year/month/XXXXXXXXXX.html
/search to /
/feed to /
XXXXXXXXXX means some text/no that are dynamic and changeable. year and month means only no that are also dynamic and changeable. / means site homepage. Rest are fixed text.
Please keep in mind that sometime there are many variables in every URL so we also want to avoid that that always start from ?variable=value&variable=value in the end of every URL.
After asking here, I keep trying myself too so I am able to do it and working on my side. I added below codes in my .htaccess file and after that I am able to redirect all upper URLs without any 404 error.
Redirect 301 /search/label http://www.example.com/category
Redirect 301 /search http://www.example.com
Redirect 301 /feed http://www.example.com
For 2,3 URL pattern, I did nothing because after checking, its not showing any 404 error as they are only variable in front of URL so no need to edit that.

.htaccess 301 redirects for part of url

I am redesigning my website and in the process restructuring some of the linking structure.
To do the permanent redirects I am using the following code (.htaccess)
RedirectMatch permanent old-link($|\.html) http://thedomain.com/new-link.url
I am using a CMS and changing the link for a category changes the path of the url like so:
thedomain.com/old-category-link/old-article-url.html
to
thedomain.com/new-category-link/old-article-url.html
How should I code (.htaccess) the redirect of any URL that has
thedomain.com/old-category-link
(i.e
thedomain.com/old-category-link/old-article.html
thedomain.com/old-category-link/old-article-2.html
thedomain.com/old-category-link/old-article-999.html
)
to
thedomain.com/new-category-link/any-articles-old-url.html
Thank you
Not exactly sure what you are asking to be redirected to, but is it something like this?
RedirectMatch permanent old-category-link(.*) http://thedomain.com/new-category-link$1
This will make is so if someone requests:
http://thedomain.com/old-category-link they will get redirected to http://thedomain.com/new-category-link
http://thedomain.com/old-category-link/ they will get redirected to http://thedomain.com/new-category-link/
http://thedomain.com/old-category-link/article1.html they will get redirected to http://thedomain.com/new-category-link/article1.html
http://thedomain.com/old-category-link/article50.html they will get redirected to http://thedomain.com/new-category-link/article50.html
No answer worked for me. Here is what is working with my Wordpress site.
Example:
OLD URL: http://website.com/xxx/yyy/picture.png
NEW URL: http://website.com/wp-content/picture.png
So, I want to replace /xxx/yyy/ with the normal /wp-content/ path of WordPress.
Put this in your .htaccess file.
RewriteEngine on
RedirectMatch 301 /xxx/yyy/(.*) http://website.com/wp-content/$1