.htaccess directory wildcard redirect - apache

Please can someone tell me why this isn't working?
I am trying to redirect all files within the directory "Kent". In this example the page to be redirected is "ramsgate" and change the folder structure.
from:
/electrical-contractors/kent/ramsgate.php
to:
/electrical-contractors-ramsgate/
Using a wildcard redirect, why doesn't this work?
RedirectMatch 301 /electrical-contractors/kent/(.*).php /electrical-contractors-$1/

Have this rule inside /electrical-contractors/kent/.htaccess:
RewriteEngine On
RewriteRule ^(.+)\.php$ /electrical-contractors-$1/ [L,NC,R=301]

Related

.htaccess - how to redirect from root to subfolder?

I have a website with URL www.somedomain.com
I want to redirect to a subfolder "folder", so that when you enter the website you are automatically redirected to www.somedomain.com/subfolder.
But I do not want the root directory to be changed, just simple redirection.
Is this possible with .htaccess ?
Is it possible to hide the /subfolder part from the URL also ?
Thanks
You can use a rewrite rule that uses ^$ to represent the root and rewrite that to your /store directory, like this:
RewriteEngine On
RewriteRule ^$ /store [L]
Just replace store with your directory

How to redirect everything to a directory?

I am organizing my public_html directory. I copied all scattered files and directories from root public_html into public_html/main directory. I would like to redirect all requests into "main" directory, basically just adding "main/" to the URL. For example:
...mydomain.com goes to ...mydomain.com/main
...mydomain.com/product_page.php goes to ...mydomain.com/main/product_page.php
*notes: Just replace the ... above with "www." because I am not allowed to post links.
I tried this rule below in .htaccess but doesn't work.
RewriteEngine On
RewriteRule ^main/?$ http://www.mydomain.com/main/ [R=301,NC,L]
Is there something wrong with that?
Thanks.
hc.
RedirectMatch 301 /(.*) /main$1

url rewrites dynamic urls redirects - Magento

I'm looking for htaccess lines that do the following
Redirect old existing urls to new url (301)
Example
www.example.com/categorya/categoryb/product.htm
TO
www.example.com/product.htm
There can be more category parts, or less, it all has to go to /product.htm (Magento).
Who can help?
Try putting these rules in the htaccess file in your document root, preferably above any rules that you may already have there:
RewriteEngine On
RewriteRule ^(.+)/product.htm$ /product.htm [L,R=301]
Try:
RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^.]+)\.htm$ /$1.htm [L,R=301]

301 redirect not working

I made a subdomain, and I am trying to redirect a page from the original domain to the subdomain, with the same dir structure.
My original page is this:
http://www.comehike.com/outdoors/alaska_hiking.php
I put this rule into the .htaaccess file under comehike.com/outdoors/ directory:
RewriteRule ^outdoors/alaska_hiking.php http://hiking.comehike.com/outdoors/alaska_hiking.php [R,L]
But as you can see from visiting the original url, it doesn't redirect. Any idea why?
Thanks!
I use apache server.
That RewriteRule line works for me when I stick it in my .htaccess file, are you sure you have RewriteEngine On?

Simple 301 redirect in .htaccess with query string does not work with Redirect directive

I am trying to redirect a single URL in a .htaccess file with Redirect:
Redirect 301 /index2.php?option=com_rss&feed=RSS2.0&no_html=1 /something/somethingelse/
I have a bunch of other similar rules which work using directory structure URLs, but this one refuses to get processed.
Redirect 301 /old/url/ /new/url/
Do I have to do anything special?
Thanks!
With Redirect you can only test for URL paths, or more specifically, URL path prefixes but not for the URL query. But you can do so with mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} =option=com_rss&feed=RSS2.0&no_html=1
RewriteRule ^index2\.php$ /something/somethingelse/? [L,R=301]