htaccess delete characters from url and redirect - .htaccess

I want to strip _/ from url.
Example: mysite.com/_/something want to redirect to mysite.com/something

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^_/(.*)$ /$1 [L,R=301]

I assume you just want to do a redirect correct?
RedirectMatch 301 ^/_/$ http://mysite.com/something
If you have Go Daddy hosting then you would have to do this:
/wordpress-testing-website/ is the folder where this testing site exists. The post name is "test_" in this example
RedirectMatch 301 ^/wordpress-testing-website/(.*)_/$ http://www.ait-pro.com/wordpress-testing-website/uncategorized/something/

Related

redirecting to a different directory using htaccess

I'm trying to redirect the following
/books/categories/mountain-literature/my-father-frank.html
to
/books/categories/baton-wicks/my-father-frank.html
This is the line in my .htaccess
RedirectMatch 301 /mountain-literature(.*) /books/categories/baton-wicks$1
it rewrites the url and appends this pageUrl stuff on which I don't want and the correct page doesn't load ?
books/categories/baton-wicks/my-father-frank.html?pageUrl=books/categories/mountain-literature/my-father-frank&contentType=html
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^mountain-literature/(.*)$ /baton-wicks/$1 [L,R=301]
try this or this
Redirect 301 /mountain-literature /baton-wicks
If you dont need the rewrite rule to match multiple URL's, try just hardcoding the target URL, i.e.
Options +FollowSymLinks
RewriteEngine On
RewriteRule mountain-literature/(.*) /books/categories/baton-wicks/my-father-frank.html [L,R=301]
By adding the [L] flag it should tell apache not to allow any other rules to append to the URI

How to not pass parameters in 301 redirect?

I want to redirect the following two links:
/catalog/yogicchai/rooibos-masala-chai-naturally-caffeine-c-84.html?infoBox=5 (category link)
/catalog/yogicchai/rooibos-masala-chai-naturally-decaffeinated-p-291.html (product link)
To:
yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html
I thought this was the solution:
RedirectMatch 301 /catalog/yogicchai/rooibos-masala-chai(.*)\.html
yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html
But the end results is:
yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html?infoBox=5
I dont want the "?infoBox=5" printed at the end of the URL above
How can I prevent that from happening?
Simply add a question mark to the target URL like this:
RedirectMatch 301 /catalog/yogicchai/rooibos-masala-chai(.*)\.html
yogicchaiDOTcom/rooibos-masala-chai-naturally-decaffeinated.html?
There cannot be two question marks in an url, so apache will not add the parameters from the previous page, because there is already one in the new.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^catalog/yogicchai/rooibos-masala-chai.*?\.html$ /rooibos-masala-chai-naturally-decaffeinated.html? [L,R=301,NC]

htaccess redirect homepage to subdirectory keep url the same

I am trying to figure out how to get my .htaccess to redirect just the homepage URL to a sub directory (domain.com > domain.com/sub/sub ), but I still want the URL to display as domain.com.
I looked around for the past hour and have tried a number of suggestions that I found but nothing worked out.
Any Ideas?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^$ /sub/sub [L]

.htaccess to redirect a specific page to root

There are several variant questions on this on SO, but I did not find one that answers my specific problem.
I want to add a rewrite rule to my htaccess that will take all traffic going to
http://example.com/blog/its-a-sunny-day
and redirect to
http://example.com
Ideally this should be done via 302, as it will be changed later.
Redirect /blog/its-a-sunny-day http://example.com
This seems to work.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^blog/its-a-sunny-day/?$ / [L,R,NC]
Create a cgi/php file for sending a redirect header. Then write a rewrite rule to replace "blog/its-a-sunny-day" with "path/to/redirect.php". For example:
/redirect.php:
<?php header( 'Location: /' ) ; ?>
/.htaccess:
RewriteEngine on
RewriteRule ^blog/its-a-sunny-day$ /redirect.php

htaccess url issue

I am trying to redirect all pages(domain.com/xxx-xxx-xxx) to new urls domain.com/np/xxx-xxx-xxx and i have tried following rule...
RedirectMatch 301 ^/([^\-]+)-([^/]+)-([^/]+) /np/$1-$2-$3/
It works but it is appending too many /np in url, check following for example
I have tried accessing http://www.domain.com/web-design-services and it becomes http://www.domain.com/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/np/‌​np/web-design-services can you please explain why is this happening?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([^-]+-[^-]+-[^-]+)/?$ np/$1 [L,R]

Resources