redirect any link to specific url (.htaccess) - .htaccess

I want to redirect
/public/courses/((anything)) to /courses
this is my code , it does not working
Redirect 301 /public/courses/.* /courses
How can I explain any link to .haccess file?

Please try following htaccess Rule. Make sure to place this rule top of your htaccess Rules file.
Please clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^public/courses/.*$ /courses [R=301,L]

Related

Redirect every trailing folder to main folder

i have a couple of unwanted urls that i want to redirect:
/faq/
/faq/question/1-title
/faq/question/2-title
I want all the /faq/question/* urls to redirect to /faq, is that possible?
I have this but this doesnt work :
RedirectMatch 301 ^/faq/question/([^/]+)/?$ /faq
With your shown samples/attempts, please try following htaccess rules file. Make sure you are putting this new rule at top of your htaccess file(after https rules(to change http --> https rules) in case there are any present in your htaccess file).
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Put your new rule here..
RewriteRule ^faq/question/ /faq? [R=301,L,NC]
###Make sure to keep rest of your urls here onwards...

302 redirect url with parameters

In htaccess file the following works
redirect 302 /old.php http://somesite.com/new.php
but following fails
redirect 302 /old.php?this=that http://somesite.com/new.php
I think it's because the second version contains a query string. How can we redirect URLs like that?
Please note the destination URL format is different so it cannot be an automated rule, so I need to write the custom URLs that users will be redirected to.
I found a similar question with replies here, but the proposed solutions do not work:
.htaccess not able to redirect url
Thank you
You may use this rule as topmost rule in site root .htaccess of old domain:
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)this=that(?:&|$) [NC]
RewriteRule ^old\.php$ http://somesite.com/new.php? [R=301,L]

301 redirection code in .htaccess to remove directory from url

I have tried alot to redirect url like
http://flexsin.org/lab/wordpress/interiorfoliage/product/cylinder/
to
http://flexsin.org/lab/wordpress/interiorfoliage/cylinder/
For this I am using this code
RewriteRule ^product/(.*)$ http://flexsin.org/lab/wordpress/interiorfoliage/$1/ [L,R=301]
but it's not working for me. i want's to remove product from url and all url as it is.
so plz suggest me where i am wrong.

How to 301 redirect example.com/http://cnn.com/page to example.com/cnn/page?

I'm setting up a project where users can get information about specific pages.
How can I redirect urls in htaccess that look like:
http://www.example.com/http://www.cnn.com/article1.html
to:
http://www.example.com/cnn/article1.html
It is ok if the htaccess specifies cnn and not all dynamic web addresses.
I tried using 301 directory redirects but I think the "http://" part of it is confusing it.
I tried using 301 directory redirects like the following code, but the http:// part is still confusing it:
RewriteRule ^http://youtube.com/(.*)$ /youtube/$1 [L,R=301]
RewriteRule http://www.example.com/http://youtube.com/(.*)$ /youtube/$1 [L,R=301]
This code below works properly to redirect example.com/youtube.com/watch?v=videoid to example.com/youtube/watch?v=videoid:
RewriteRule ^youtube.com/(.*)$ /youtube/$1 [L,R=301]
but if the user types in a link with http:// in it then the server cannot currently redirect properly.
Even better, if you can remove the /http:// and /https:// altogether from http://example.com/http://url.com and http://example.com/https://url.com to redirect to http://example.com/url.com/ then the redirect code that I have working in the youtube example will fix the issue for all of the domains.
How can I do this?
Thank you!

Using htaccess to change url

I want to change a url like:
dynamicdomain.com/mypage
to
dynamicdomain.com/mydashboard
I want to display the content of mypage but the url that the users will see on the browser will contain mydashboard. How do I do this using .htaccess.
I tried using this:
RewriteEngine On
Redirect 301 /mydashboard /mypage
but this redirects the url:
dynamicdomain.com/mydashboard
to
dynamicdomain.com/mypage
Edit:
Here is another example on what I want to achieve:
I have a folder mypage which can be accessed as:
http://dynamicdomain.com/mypage/
I want the users to see http://dynamicdomain.com/mydashboard/
(mydashboard folder doesn't exists) when they access http://dynamicdomain.com/mypage/
can someone point me in the right direction.
Thanks.
Try these directives:
RewriteEngine On
RewriteRule ^mypage$ /dashbord [NC,L]
Redirect directive does an external redirect (redirects a URL to another URL). To redirect "dashboard" internally to "/mypage", you need to use the RewriteRule directive of the Rewrite module.
Put this in your htaccess file :
just after IfModule closes
Redirect 301 /mypage http://www.dynamicdomain.com/mydashboard
This will work for you.
thanks

Resources