Need a an htaccess substution recomendation - .htaccess

Want a simple htaccess to redirect html root filename to a sub-directory.
www.xyz.com/About****.php where **** is arbitrary. The words "About" and ".php" are fixed
convert to www.xyz.com/coach/articles/About****.php
Haven't used regular expressions and htaccess for many years. Relearning curve is time consuming.

This will redirect every URL that matches About****.php to coach/articles/About****.php
RewriteEngine On
RewriteRule ^About(.*).php$ coach/articles/About$1.php [L,R=301]

Full example:
https://riderxxx.org/About_How_To_Select_Your_Performance_Training_Courses.pdf
Result:
https://riderxxx.org/Coach/Articles_pdf/About_How_To_Select_Your_Performance_Training_Courses.pdf
The article is in /Coach/Articles_pdf/ But, users are having trouble dealing with the full URL

Related

.htaccess regex redirect avoid by file type

I have two URL conditions and I wanted to redirect them like this:
https://www.example.com/feeds/4aceXy to https://www.example.com/direct_feed/4aceXy
Now the problem is, I am also using the URL for an older link like this one:
https://wwww.example.com/feeds/5bdb39711b41d479273e678a6f356603d7109ffc.xml
I wanted to avoid redirect with .xml extension here is my current redirect:
RewriteRule feeds/(.*)?$ https://wwww.example.com/direct_feed/$1 [QSA,L]
It works fine but I don't want to redirect it with .xml based URL.
My question is - is there a condition that can help me to avoid the rewrite if a parameter contains .xml in regX (.*)?$
You can use a negative lookbehind:
RewriteRule feeds/(.*)?(?<!\.xml)$ https://wwww.example.com/direct_feed/$1 [QSA,L]

Ho do I write an .htaccess redirect for a directory containing an ellipsis

Some how I had an invalid directory indexed in Google, and because of some dynamic relative links I now have 2500 "missing" pages indexed. I'm trying to use an .htaccess 301 redirect to correct the problem but I can't seem to get it to work. I need to redirect www.domain.com/shop/pc/.../pc/filename.asp to www.domain.com/shop/pc/filename.asp.
The rule I have written that doesn't want to work is RewriteRule ^shop/pc/\.\.\./pc/(.*)$ /shop/pc/$1 [R=301,L]
Any thoughts?
mod_rewite uses PCRE, so for these Unicode characters (I included the two dot leader as well, since I imagine that is more likely to sneak into a URL than an ellipsis):
# U+2026 … \xe2\x80\xa6 HORIZONTAL ELLIPSIS
RewriteRule ^shop/pc/\xe2\x80\xa6/pc/(.*)$ /shop/pc/$1 [R=301,L]
# U+2025 ‥ \xe2\x80\xa5 TWO DOT LEADER
RewriteRule ^shop/pc/\xe2\x80\xa5/pc/(.*)$ /shop/pc/$1 [R=301,L]
Note you may need the [B] flag (see flags) if the browser is percent-escaping the ellipsis.

htaccess 301 redirect all website pages with query to /

In the past website was full of pages with different basis. After redisign and with new concept the website consists of only 1 page. So I need to redirect all old pages to /.
Pages for example:
http://domain.com/catalog/index.html?c_id=145
http://domain.com/catalog/?c_id=116
http://domain.com/news/read.html?id=174
and so on.
In htaccess I've made several rules like this:
RewriteRule ^catalog(.*)$ http://domain.com/ [L,R=301]
But this rule don't give a full control, and the result is not satisfactory:
http://domain.com/?c_id=145
How can I get rid of this? I need to redirect all such links to http://domain.com without any additions. I think the {QUERY_STRING} can help, but I don't know how to do this correct.
Any help would be appreciated. Thanks!
You can add a ? at the end to create a blank query string:
# append "?" here ----v
RewriteRule ^catalog(.*)$ http://domain.com/? [L,R=301]

How to 301 redirect pages "up" a page

I'm a newbie and I'm trying to figure out the proper 301 redirect for the following pages. I hope I'm being clear here :) In my .htaccess file, I want to redirect pages "up" one pages without having to do every page individually.
My original pages looked like the following:
www.doctors.com/skin/california/best-skin-doctors-california/
www.doctors.com/skin/california/best-skin-doctors-california/?page=1
www.doctors.com/skin/california/best-skin-doctors-california/?page=2
....etc. ....up to like /?page=33
and more categories and states, like:
www.doctors.com/heart/new-york/best-heart-doctors-new-york/
www.doctors.com/heart/new-york/best-heart-doctors-new-york/?page=1
www.doctors.com/heart/new-york/best-heart-doctors-new-york/?page=2
...etc. .....again up to like /?page=24
I've since changed the page structure to eliminate the long URLs...like this:
www.doctors.com/skin/california/
www.doctors.com/skin/california/?page=1
www.doctors.com/skin/california/?page=2
etc.....and similarly....
www.doctors.com/heart/new-york/
www.doctors.com/heart/new-york/?page=1
www.doctors.com/heart/new-york/?page=2
etc.
How can I "bulk" redirect the original pages with the long URLs to the newer, shortened version in my .htaccess file? Thank you very much for your time and consideration!
Using mod_alias, you can simply add this in the .htaccess file in your document root:
RedirectMatch 301 ^/([a-z\-]+)/([a-z\-]+)/[a-z\-]+/$ /$1/$2/
But if you need further restrictions on how the redirect works, you can use Apache's mod_rewrite module. Taking a look at the RewriteCond directive, you can impose conditions on a rule and put everything in .htaccess. The main rule will look very similar to mod_alias' RedirectMatch. Example:
RewriteRule ^([a-z\-]+)/([a-z\-]+)/[a-z\-]+/$ /$1/$2/ [R=301,L]
In both cases, the query string (the page=3 part) is simply appended to the new target. Looking over the different things you can do with RewriteCond, say if you wanted to exclude this rule when requests are made for something like /images/ or /themes/:
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !^/themes/
RewriteRule ^([a-z\-]+)/([a-z\-]+)/[a-z\-]+/$ /$1/$2/ [R=301,L]
So, if the request doesn't start with /images/ and the request doesn't start with /themes/, then apply the rule. This example would make it so a request for http://host.com/themes/subSilver/magic-icons/ don't get redirected to http://host.com/themes/subSilver/.

.htaccess Redirect sub-folder

Hi I'm not a programmer by any stretch of the imagination and am trying to do a multi 301 redirect in my htaccess file based on the following:
So I have a ton of urls all with similar naming conventions - here is a sample of 2.
http://www.hollandsbrook.com/garrett-at-gold/
http://www.hollandsbrook.com/garrett-ace-250/
These urls need to redirect to:
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-at-gold/
http://www.hollandsbrook.com/garrett-metal-detectors/garrett-ace-250/
I could just redirect them 1 line at a time, but I'd like to use regex.
Here's what I was thinking so far but not working:
RewriteRule ^garrett-([a-z])/$ /garrett-metal-detectors/$1/ [R]
Basically i need to redirect any page right off the root that starts with "garrett-" to include the folder path of "garrett-metal-detectors".
Any thoughts would be MUCH appreciated. Many thanks in advance for your help.
if you want temprorary redirect use:
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=302,L]
if you want permanent redirect use:
RewriteRule ^garrett\-([a-z0-9\-]+)/?$ /garrett-metal-detectors/garrett-$1/ [R=301,L]
I'm am not an expert on Regular Expressions, but looks like your reg ex may be a bit off...
try:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^((garrett)(-[a-z0-9]).*)/$ /metal-detectors/$1/ [R]
This is looking fro anything starting with "garrett" followed by any letter/number/hyphen combo.
Note: having "garett" in the destination part give you a loop of redirects, so you may have to choose a different word, or remove it all together...

Resources