How To Remove Redundent ?p=1 From URL - apache

So I had an issue where my pagination would append a ?p=1 to the end of a URL when moving from page 2 back to page 1. With the issue corrected so those links no longer get served, I do have to try and find a way to do a 301 redirect from those URLs to the proper URL so that the search engines can update those links.
I am on an Apache server, and I would like to be able to use RedirectMatch 301 to do this, however I do not think that it plays well with query strings.
RedirectMatch 301 (.*)?p=1 http://mydomain.com/$1
does not do the trick
I believe the solution is going to end up being that I use RedirectCond and Rewrite statements to make this work, however I do not know how to get this to redirect.
Can someone help me out with this? What I have so far gives me Internal Server Errors so obviously I am not on the right track yet.
RewriteCond %{REQUEST_URI} (.*)$
RewriteCond %{QUERY_STRING} ^?p=1$
RewriteRule ^.*$ http://devserver/$1 [L,R=301]
If someone can even point me toward a good tutorial on how to set this up would be helpful too.

RewriteCond %{QUERY_STRING} (^|&)p=1(&|$)
RewriteRule . http://devserver%{REQUEST_URI}? [L,R=301]

Related

Why http://www. goes to /index.php and https://www. does not?

I'm running into a strange error causing poor SEO results.
Everything works expect when using http://www. it shows /index.php
but, https://www. or http:// or https:// does not show index.php
This is my rewrite conf
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https\:\/\/domain\.com\" [R=301,L]
If you have search console you could check what is wrong with your domain.If you couldn`t find any problem my advice is to find good SEO agency. http://www.asknatewang.com/ There is a chance your ranking to be affected because of the discrepancy.
Greetings!

Redirect subirectories without affecting the main directory

While updating things in WordPress I found that plugins that generate slugs can't use a slug that's already in use by another page so I have had to change the slug to be something slightly different. I now need to make sure that anyone that tries the old urls get redirected to the new one without affecting the main page.
So I have /members/ with a list of members and you can click members to go to /member/[name] I need to redirect /members/[name] to the /member/[name]
( [name] can be anything so it needs to be a wildcard.)
I have used both of the following htaccess rules (not at the same time) but they always end up redirecting the /members/ page also which breaks everything.
RewriteRule ^members/(.*) http://domain.tld/member [R=301,L]
RedirectMatch 301 ^/members/.*$ http://domain.tld/member
What am I missing to make it only redirect if there's something after the /
Sidenote: I've tried finding an answer to this but all the results I have found are trying to do the exact opposite (redirecting only the exact match of /members/) that I need and wont work.
You are not using the captured part of the request.
Try :
RedirectMatch ^/members/(.+)$ /member/$1
Try this
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Redirect 301 /oldDir/old.php http://yourDomain/newDir/new.php

htaccess removing a specific address with a query string

I have a site where the issue has come up where I am getting a 404 error on a specific site URL with a query string. This isn't I a site I work on frequently so I am not sure if any queries should still be used. I tried this myself and it didn't work.
Redirect 301 /category.aspx?id=MISC34 /
I want the 301 direct to be specific to www.example.com/category.aspx?id=MISC34 to go to the homepage. This did not work for me. It is on Wordpress if that matters.
I am not that well versed in htaccess. Any help would be apperciated.
You can use in your .htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)id=MISC34(&|$) [NC]
RewriteRule ^category\.aspx$ /? [L,NC,R=301]

301 Redirect Whole Site Except One Folder, leave Add-on domains alone

I have a brainteaser and need help from people smarter than me. I have a shared hosting account. I'd like to 301 forward the root URL (say, domain.org) to a new URL. I also want one folder (/blog/) to be left alone (not forwarded). I was able to find an example of this here, and I put together this potential scenario for doing that:
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
I believe that this should be OK, but here's the trick: I have add-on domains in this hosting, and if I use the above, I'm pretty sure that I will forward every one of them to newdomain.org, not just domain.org. I did some testing using more specific text strings in the first spot following RewriteRule, but I can't seem to get the syntax without blowing up my site and getting a 500.
Any ideas would be greatly appreciated!
Thanks, Dave
Try adding another condition:
RewriteCond %{HTTP_HOST} ^domain\.org$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
Where domain.org is the domain that you want everything to be redirected to newdomain.org, except /blog/.

Beginner's apache mod_rewrite assistance

I am not really familiar with apache mod_rewrite.
I have url parameters such as {domain}/index.php?blog=5
I simply want to make it {domain}/home.php?client=5
Is it a task as simple as it sounds and can anyone help?
The following might work, give it a try
RewriteCond %{REQUEST_URI} ^/home.php [NC]
RewriteCond %{QUERY_STRING} client=([0-9]+) [NC]
RewriteRule (.*) http://%{REMOTE_HOST}/index.php?blog=%1 [L]
That seems pretty simple, to be honest — once you get your head into mod_rewrite, it's not that complex.
It sounds like you want to add
RewriteEngine on
RewriteRule ^/index.php?blog=(.+)$ /home.php?client=$1
to your configuration.
Some caveats:
If you are putting this in a .htaccess file, then remove the / from the RewriteRule line.
If you want to make this case-insensitive, add [NC] to the end of that same line.
If you want users to see the URL change (so sending a 302 Found redirection to the browser), then add [R] to the end of the RewriteRule line.
If you want both a 302 Found and for the URL to be case-sensitive, combine the two instructions as [NC,R] at the end of the RewriteRule line.
It's definitely worth reading the mod_rewrite docs, but the rule above should be all you need for this use-case.