301 Redirect all ?p=xxx to frontpage - apache

We just got our new site up and running. But now I'm trying to sort out the redirects with .htaccess.
Most of them work, but the once with /?p=xxxx wont redirect to mysite.com/something/ now I don't know what all the ?p=xxxx pages are so I just want them to redirect to the frontpage.
Anyone know how to do that. I have seen a lot of these codes. But non of them work for me:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
If anyone can help, thanks!

You can use the following :
RewriteEngine On
##non-www to www##
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
##redirect "\?p=xxx" to "/frontpage"##
RewriteCond %{THE_REQUEST} \?p=[^\s]+ [NC]
RewriteRule ^ /frontpage/? [L,R]

Related

REWRITE RULE reacts strange

I have the following
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteRule ^gl/(.*)/$ gl/index.php?nav=gl&d=$1 [NC,L]
this makes that for example a request to
https://www.example.com/gl/de/
is redirected to
https://www.example.com/gl/index.php?nav=gl&d=de
so far so good. Now I want to redirect
https://www.example.com/gl/de/?var=val
to
https://www.example.com/gl/index.php?nav=gl&d=de&var=val
can you help please ?

Rewrite Rule in Apache/htaccess not working

I'm trying to redirect user request to my domain in .htaccess file.
My requirement is for example if user request for example.co/abc it should redirect to www.example.co/abc.
Below is my rewrite rule.
RewriteCond %{HTTP_HOST} ^example.co/Abc [NC]
RewriteRule ^(/Abc)$ https://www.example.co/$1 [L,R=301]
After adding the above two lines in my .htaccess file it is redirecting from example.co to www.example.co
I tried in different ways still not getting where i'm doing mistake.
Any help would be appreciated.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.co [NC]
RewriteRule ^(.*)$ http://www.example.co/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{www.example.co} [L,R=301]
RewriteCond %{HTTP_HOST} ^example.co [NC]
#RewriteRule ^(/*)$ https://www.example.co/$1 [L,R=301]
RewriteRule ^/?(Abc)/?$ https://www.example.co/$1 [L,R=301]

Redirecting to https for any URI

In my .htaccess file, I have the below.
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301]
This works fine until someone goes to http://www.example.com/test because that does not force a redirect to https.
Is there a better way of doing this?
Yes, change your last two lines to:
RewriteCond %{HTTP_HOST} !^(www\.example\.com|)$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

rewrite www. to without www. in .htaccess for hostname instead of writing in the website name?

I currently use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.e-innovate.co.uk [NC]
RewriteRule ^(.*)$ http://e-innovate.co.uk/$1 [L,R=301,NC]
But what i am trying to do is create a general rewrite code which i can drop into .htaccess files without having to change the domain name such as below, i dont seem to be able to get this to work, am i on the right track ?
Thanks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
note that this will also get applied to subdomains.

.htaccess Exclude directory in rewrite

I want to exclude URL rewriting if the directory is mysite.com/admin. I have tried:
# prepend http://www.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^m\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(admin|user)($|/) - [L]
I'm not too familiar with this stuff, but I can't seem to get this working. Does anyone see the solution?
Try moving the pass-through for the admin | user directories before the redirect:
RewriteEngine On
RewriteRule ^(admin|user)($|/) - [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^m\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Other than that, I don't see any rewriting going on at all, so I'm not sure what they need to be excluded from.