Remove query strings from 301 redirect - apache

I am struggling to create appropriate 301 redirects for a site that was originally built using query strings. The old URL structure looks like this:
http://www.oldsite.com/about/index.cfm?fuseaction=cor_av&artID=5049
I want to redirect the entire subfolder (named 'about') to a new page on the new domain. The new domain's URL looks like this:
http://www.newsite.com/info
So, I set up a redirect that looks like this:
redirectMatch 301 ^/about/ http://www.newsite.com/info
It is redirecting just fine, but it's keeping the original URL string attached, so the new URL ends up looking like this in a browser:
http://www.newsite.com/info/?fuseaction=cor_av&artID=5049
I'm definitely not enough of an Apache/301 expert ot know how to fix this. I just want to strip off everything from the ? on.
Really appreciate any help.

two options:
redirectMatch 301 ^/about/ http://www.newsite.com/info?
or:
RewriteEngine on
RewriteRule ^about/(.*) http://www.newsite.com/info? [L,R=301]
question mark at the end seems to be the critical bit. Second one looks a little cleaner (first leaves a question mark at the end of your URL)

Try to add this code into the .htaccess that specified for oldsite.com:
RewriteCond %{REQUEST_URI} ^/about/index.cfm$
RewriteRule ^(.+) http://www.newsite.com/info/ [R=301,QSA]
Follow up?

Related

Redirecting a URL that contains a specific part to another URL using htaccess

I would like to know if there is a way to redirect a URL that looks like this:
https://www.example.com/p=d3d82c7c
to
https://www.example.com/polls/poll?poll=d3d82c7c
using htaccess.
What I want to do is to create a more simple link for the users. Is that possible with htaccess only?
PS: the code at the end may change within each URL.
Thank you very much.
With your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^.*=(.*) polls/poll?poll=$1 [L]
OR with your shown samples if your URI always starts with p then you could try following, but make sure either previous OR this only one of them should be used at a time.
RewriteEngine ON
RewriteRule ^p.*=(.*) polls/poll?poll=$1 [L]
You can use this method:
Redirect 301 /en/php/project.html http://www.example.org/newpage.html

Trying to redirect anything after the full URL without /68 for example

I need to remove anything on the end of URLs like the below examples without the /68 or any number ID
https://www.website.com/forum/making-coffee/68 <-- I would like to remove the / and anything after so it looks like this below.
https://www.website.com/forum/making-coffee
I've searched but can't get the redirect to work correctly.
Any idea?
You can use this rule in your root .htaccess
RedirectMatch 301 ^/(.+?)/[0-9]+$ /$1

How to set the right conditions in htaccess file?

I've tried for ages to fix this problem that I have.
On my website I have rewriten some links with the htaccess file. The htaccess file currently looks like this:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?sideID=$1
RewriteRule ^([a-zA-Z0-9_!-]+)/([a-zA-Z0-9_!-]+)/([a-zA-Z0-9_!-]+)$ index.php?sideID=$1&id=$2&title=$3
RewriteCond %{HTTP_HOST} ^www\.mypage\.no$
RewriteRule ^/?$ "http\:\/\/mypage\.no\/" [R=301,L]
The first rule rewrites from:
http://mypage.com/index.php?sideID=home
To this:
http://mypage.com/home
The first rule rewrites from:
http://mypage.com/index.php?sideID=b&id=12&title=a-great-blog-post
To this:
http://mypage.com/b/12/a-great-blog-post
Soo they do what I want too when it comes to rewriting I guess. BUT, the problem is that if im now navigated to any blog post on the site and then tryies to navigate back to whatever other link lets say http://mypage.com/home it will add http://mypage.com/b/12/home instead. That can of course be fixed easily by just using absolute URL's in the navigation. But when I try to make a XML Sitemap, the bot will index every page for each blog ID like so: http://mypage.com/b/12/home, http://mypage.com/b/13/home, http://mypage.com/b/14/home and so on for each blog ID and pagename.
Is there a way to make sure the RewriteRule's apply seperatly or set a condition for them or something like that?? I am a bit noob in this area.
I beg you, please help me! :)

301 redirects for urls ending in numbers and contain folder name

I want to place 301 redirects from old urls which look something like
http://www.domain.com/news/blocked-drainage/drain-cleaning-companies-help-in-restoring-your-clogged-drains/408
To
http://www.domain.com/blocked-drainage/drain-cleaning-companies-help-in-restoring-your-clogged-drains/
so two changes, firstly now news folder in new urls and secondly no numbers at the end of the urls.
Thanks for the help in advance.
Try this:
RewriteRule ^news\/(.+)\/([0-9]+)$ /blocked-drainage/$1/ [R=301]
(Novocaine88’s answer won’t work, because RewriteRule only tries to match against the path component of the URL.)

Rewrite To WordPress Page

I have an existing page of /programs/kids.php that I want to load a category page from WP. I want the .htaccess file in /programs to handle this rewriting for me.
Something along the lines of:
RewriteEngine on
ReWrite kids2.php http://www.mysite.com/blog/cat/kids/
Any help would be awesome.
If your sure mod_rewrite is enabled by apache, the it is simple as
RewriteEngine on
RewriteRule kids.php http://www.mysite.com/blog/cat/kids/
or
RewriteEngine on
RewriteRule ^programs/kids.php$ http://www.mysite.com/blog/cat/kids/
depending on location and strictness (^hhh$ matches the whole string)
The directive is named RewriteRule and not just Rewrite. So try this:
RewriteRule ^programs/kids2\.php$ /blog/cat/kids/
But if you want have requests to /blog/cat/kids/ rewritten internally to /programs/kids2.php (the exact opposite of what you’ve mentioned), try this rule:
RewriteRule ^blog/cat/kids/$ programs/kids.php [L]
You could also do an include for that kids.php in the content of an existing WP page, but you'd need the ExecPHP plugin installed.
Then kids.php would display as styled content inside a WordPress page. Which is sometimes desirable, from a site cohesiveness standpoint.
Something like this:
<?php require_once(ABSPATH. '/programs/kids.php');?>
Not exactly what you asked for, but maybe an alternative approach.