Redirect URL with a parameter to homepage - apache

Recently we have released a new website for a company but some of the old links still apear on google webmaster tools.
I tried to create a redirect with some luck, however I want to fully remove the parameter and redirect all the links matching the structure to the new homepage.
So these pages
http://www.example.com/job/view.php?id=142
http://www.example.com/job/view.php?id=3453
http://www.example.com/job/view.php?id=567
will redirect to
http://www.example.com
I used this redirect
RedirectMatch 301 /job/view.php$ http://www.example.com/
which works OK with the exception that the resulting website looks like:
http://www.example.com/?id=142

You can try this way
RewriteEngine on
RewriteRule ^job/view\.php$ http://www.example.com/? [R=301,L]

Related

Redirect with .htaccess to exact URL provided

So I want to redirect from old sites url to new one. Lets say example.com/en/some/stuff/foo/bar needs to be redirected to example.com/some/stuff.
Here is what I have at he moment:
Redirect 301 /en/some/stuff/foo/bar/ /some/stuff/
The problem is that I end up being redirected here example.com/some/stuff/foo/bar, but I need as I defined inside .htaccess example.com/some/stuff.
How to redirect properly to exact URL I have provided without anything extra.
You can use this redirect rule with regex in your site root .htaccess:
RewriteEngine On
RewriteRule ^en/(some/stuff)/.+ /$1 [L,NC,R=301]
Make sure to test it in a new browser to avoid old cache.

redirect specific category pages to subdomain

I have been trying this for a while but haven't found a solution yet.
I moved to wordpress and my old site is in custom CMS. the old site now goes to archive.example.com while all the new posts will be created on http://example.com
I have created different categories for new site so that it doesn't conflict with categories from old site.
I want all the request being made to old category pages to go to archive.exampmle.com
For eg:
http://example.com/apple
should go to
http://archive.example.com/apple
Also,
all the URLs under apple category should go to the archive subdomain. For eg:
http://example.com/apple/1234
should now go to
http://archive.example.com/apple/1234
I tried this
RedirectMatch 301 /apple/ http://archive.example.com/apple/$1
but it doesen't work.
Try with below rule,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^apple
RewriteRule ^ http://archive.example.com%{REQUEST_URI} [R=301,L]

Redirect 301 dynamic news htaccess

I changed the URL structure for a website. Now I want to create a 301 rule in the .htaccess so if anyone is using the old URL via google for example it will be redirected to the homepage.
The old structure was /category/[article name] and sometimes /category/sub-category/[article name] now if use the following rule
Redirect 301 /category/ http://example.com/
It is only working when I type in /category/ wich is logic. So I tryed
Redirect 301 /category/(.*) http://example.com/
This is not taking effect. So my question is how can I redirect every URL when an URL is entered like my example above. So it doesn't matter what comes after /catagory/ it needs to be redirected so google will remove my URL's from the index and will index the new ones with the new sitemap I uploaded.
Thanks
You can't use Redirect like that, you would need to use RedirectMatch but sometimes it's problematic.
If you want to have more control and power over your redirects I would suggest using mod_rewrite.
RewriteEngine On
RewriteRule ^category/(.*)/?$ http://example.com/ [R=301,L]
This will get you what you want and it always works for me.

.htaccess redirecting only pages with no subfolder

I am using .htaccess to redirect pages from an old website to a new site. The URL structure has changed completely, but thanks to a SEO person I have a complete list of URLs I have to redirect and take care of.
My .htaccess looks like the following:
Options +FollowSymlinks
RewriteEngine On
Redirect 301 /some-guy http://www.new.domain/kontakt/
Redirect 301 /some-other-guy http://www.new.domain/kontakt/
...
Redirect 301 /de/some-page http://www.new.domain/some/subpage/
Redirect 301 /de/another/page http://www.new.domain/nice-page/
Of course the URLs can be even longer and contain query strings and stuff like that. The new website has a different URL structure and does not need query strings and nothing.
Now, while the first two redirects work perfectly, every redirect which contains a subfolder fails to redirect to the target location. The last URL for example redirects to
http://www.new.domain/de/another/page
What am I missing here?
Try
Redirect 301 ^de/another/page http://www.new.domain/nice-page [L]
I got it working now with little modifications to Anup Saunds code (and therefore using mod_rewrite).
I used the following structure which seems to work fine with all links I have and sets the status code for search engines.
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^what/ever/your/path-is(.*)$ http://www.new.domain/oh-what/a-nice-path/ [R=301,nc]

htaccess permanent redirect and remove string from url

How can I go about getting visitors who enter the site via a mobile url get redirected to the non mobile url on this example;
user visits http://website.com/*mobile/*the-page.html
redirect them to http://website.com/the-page.html
Doing a google search, I was able to come up with the follow htaccess line:
RewriteRule ^/?mobile/(.*)$ /$1 [L,R=301]
though it correctly redirects to the right page, it uses the filename of the dynamic page to do so, example:
http://website.com/index.php?id=the-page
how can I get it to just take out mobile/ from the url?
okay, slow moment... I needed to deleted the original rewrite rules for the mobile site.
after that, it was simple as adding
RewriteRule ^mobile/(.*)$ /$1 [L,R=301]
to htaccess.