Redirect every trailing folder to main folder - .htaccess

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...

Related

redirect any link to specific url (.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]

Redirect everything after domain.com/articles.php

So i have this issue, with changing an old site with a new and I need to redirect all the old links. So have this:
domain.com/articles.php?var=1
I basicly want to redirect everything after articles.php to just domain.com, including the /articles.php.
Thank you in advance.
Try adding this to your htaccess file:
RedirectMatch 301 ^/articles\.php$ /
or if you have mod_rewrite rules already in your htaccess file, you need to use mod_rewrite isntead, and add this rule above whatever rules are already there:
RewriteRule ^articles\.php$ / [L,R=301]

Duplicate pages 301 redirects changing destination url

I have some dupilcate pages in my Joomla site.
Examples
/80-games
/80-games?start=12
/80-games?start=20
I did a 301 redirect in my .htcaccess for the first one which works fine.
My redirect for /80-games
Redirect 301 /80-games http://www.teach-this.com/esl-games
But for /80-games?start=12
The url changes to http://www.teach-this.com/esl-games?start=12
What should my redirect be for /80-games?start=12
Somehow the question mark is causing my destination url to change.
Thanks
Paul
You should use mod_rewrite as you cannot manipulate QUERY_STRING using mod_alias rules.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^80-games/?$ http://www.teach-this.com/esl-games? [R=301,L,NC]
Note ? at the end of target URI that is used to strip out any existing QUERY_STRING in the original URL.

htaccess not redirecting because of '?'

I'm having a problem with my htaccess, we've moved a website and they're old website had a lot of duplicate pages that had a ?cat_id=88 etc... on them, I'm trying to redirect the page but it's not working, I've put the redirect code below, I'm already redirection the mantra.html to the /Mantra but the version with the ?cat_id=79 isn't redirecting, it's just ignoring everything after the ?
Redirect 301 /mantra.html?cat_id=79 http://www.website.co.uk/Mantra
Redirect only accepts paths, not paths with querystring. You could use mod_rewrite
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cat_id=79$
RewriteRule ^mantra\.html$ /Mantra? [R=302,L]
change 302 to 301 once you get it working (301 are aggressively cached by browsers and make debugging a nightmare).
EDIT added a ? at the end to remove any querystring. Apache removes the ? if there is no other data in the querystring, so the end user will never see it.

How do I do a Htaccess 301 redirect with dynamic files

I've tried many many methods of this but none seem to work.
I upgraded my site to PHP from ASP and as a result now I have 300+ 404's which i should of seen coming, but oh well.
Problem is I need to redirect these files and they are all dynamic:
old files are like: http://www.domain.co.uk/resoucecentreDetails.asp?title=foobar&ID=37
There are literally 100s of these so is there a quick way I can redirect them to a single page i.e. http://www.domain.co.uk/resoucecentreSelect.php
You can use Rewrite Rules in .htaccess.
Write following Rule in your htaccess.. It will redirect all your dynamic URLs to one page..
RewriteRule ^resoucecentreDetails.asp?title=(.*)&ID=(.*)$ /resoucecentreSelect.php [L,R=301]
This rule will do the job:
# activate rewrite engine
RewriteEngine On
RewriteBase /
# redirect rule
RewriteRule ^resoucecentreDetails.asp$ http://%{HTTP_HOST}/resoucecentreSelect.php [NC,QSA,R=301,L]
It will redirect all requests from /resoucecentreDetails.asp to /resoucecentreSelect.php preserving the query string, e.g.:
http://www.domain.co.uk/resoucecentreDetails.asp?title=foobar&ID=37
will become
http://www.domain.co.uk/resoucecentreSelect.php?title=foobar&ID=37

Resources