Custom .htaccess hidden 301 redirect - apache

Is it possible to write in one rule the redirecting for each brand alias to an equivalent get-parameter?
For example:
"/katalog/protein/api/" must be redirected to "/katalog/protein/?ms|manufacturer=API",
"/katalog/protein/activelab/" must be redirected to "/katalog/protein/?ms|manufacturer=ActiveLab"
I'm looking for something like that in .htaccess:
RewriteRule ^katalog/(protein|gainer)/(api==API|activelab==ActiveLab)/?$ /katalog/$1/?ms|manufacturer=$2 [R=301,L,QSA,NE,NC]
Is it possible? Thank's for any help.

Related

Rewrite rule to redirect from http to https without extension

I can access url without extension i.e I can access
'www.example.com/signUp/save' and 'https://www.example.com/signUp/save'
Now I am trying to redirect the following:
'www.example.com/signUp/save.php' to 'https://www.example.com/signUp/save.php'
'www.example.com/signUp/save' to 'https://www.example.com/signUp/save'
using this rule:
RewriteRule ^signUp/(.*)$ https://%{HTTP_HOST}/signUp/$1
I am able to rewrite the first one but not the second. Also after writing this rewrite rule in my .htaccess file I get 'Not found' for 'www.example.com/signUp/save'
What is the correct way of doing this?
Try this:
RewriteRule ^signUp/([a-zA-Z0-9]+)(\.[a-zA-Z0-9]+)?$ https://%{HTTP_HOST}/signUp/$1

Apache - redirect only the domain URL to a subpage

I have a shared hosting Apache server, and I'm trying to send visitors who come to the main domain URL to a specific page, with the URL replaced and a 303 redirect:
example.com
example.com/
to
example.com/subdirectory/page.html
Only the plain domain URL should get redirected, not:
example.com/page.html
example.com/otherdirectory
example.com/otherdirectory/
example.com/subdirectory
example.com/subdirectory/
example.com/subdirectory/otherpage.html
example.com/subdirectory/otherdirectory
example.com/subdirectory/otherdirectory/
example.com/subdirectory/otherdirectory/page.html
I'm not sure that RewriteEngine is allowed on this server, if there are alternative approaches possible.
The crude way I've thought of is to just use DirectoryIndex to send the visitor to example.com/index.php -- and have a PHP redirect in that file go where I want. But I'm not sure if this might produce a visible blip for some visitors, or how Google would feel about it.
I've found other instances of this kind of question on Stack Overflow, but the answers are failing for me in some way or another. As the behavior is not intuitive, testing before posting might be advisable.
Thanks
If mod_rewrite is not enabled you can use mod_alias based rule like this in your DocumentRoot/.htaccess:
RedirectMatch 303 ^/?$ /subdirectory/page.html
UPDATE: Equivalent mod_rewrite rule:
RewriteEngine On
RewriteRule ^/?$ /subdirectory/page.html [L,R=303]

Redirect to new URL`s

i want Redirect the old url`s to new address.
Redirect all
http://www.mysite.com/viewdownload/**/**
url`s to
http://www.mysite.com/download/viewdownload/**/**
example:
http://www.mysite.com/viewdownload/21/323
Should be Redirect to
http://www.mysite.com/download/viewdownload/21/323
or
http://www.mysite.com/viewdownload/13/961
Should be Redirect to
http://www.mysite.com/download/viewdownload/13/961
RewriteRule ^(viewdownload)/(\d+)/(\d+)/?$ download/$1/$2/$3 [L,R=302,QSA]
If this does what you'd like it to after some testing, change R=302 to R=301.
If you are using Apache this is something for mod_rewrite / url rewriting & not Joomla.
You got the wrong keywords. Search for mod_rewrite or come back if you need more help.

Apache rewriterule to redirect folder to subfolder without loop

Long story short, I am trying for the last 3 hours to perform what seems to be a basic url redirect. All the website requests to mysite.com/folder should be redirected to mysite.com/folder/subfolder/. The redirect should be performed "only!" if the user enters /folder. If he accesses /folder/file no redirect should happen.
I have tried the following but with no success, all attempts cause an infinite loop:
RewriteRule ^/folder$ /folder/subfolder/ [R]
Redirect 301 /folder /folder/subfolder/
I don't have access to the vhost file, neither am I allowed to perform this using php or a similar 'workaround'. Either way, htaccess should be the best place to do this. Can anybody shade a light on what I am doing wrong?
redirect use a prefix pattern matching, so instead you should use RedirectMatch with a regex, so that you will match only the directory access and not the file access in the subdirectory. You do not need the rewriteRule, which is doing the same thing.
This should work:
RedirectMatch ^/folder/$ /folder/subfolder/
Be careful, you used a 301 Redirect, 301 means permanent, so you may need to close your browser before testing the new rule, your browser has memorized the redirect permanent answer and will not ask it again until you close it.

.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