.Htaccess redirect index.php - php

I transfered an old bulletin board to q2a.org. Now i have a lot index.php files in google which do as 200 OK Status. How can I redirect those links to root? ex. www.domain.com/index.php?page=Board&boardID=14 or www.domain.com/index.php?page=Thread&postID=58585
This is my current .htaccess file
ErrorDocument 404 /404.php
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
Thanks

Insert this rule just after RewriteBase line:
RewriteCond %{QUERY_STRING} page=[^&]+&postID=[^&]+ [NC]
RewriteRule ^ /? [R=301,L]

Related

.htaccess redirection with multiple rules

Basically what I want to do is :
1) redirect any .html request to .php page.
2) if any 404 happens , then it should redirect to www.domain.com
3) domain.com should be redirected to www.domain.com
4) www.domain.com/index.html should redirect to www.domain.com
Here is my htaccess code
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^fr/(.)*$ / [R=301,NC,L] # Added line
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . http://www.domsdain.com/index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]
With above code 4th rule (www.domain.com/index.html should redirect to www.domain.com) is not working
You can refactor to use these rules:
ErrorDocument 404 http://www.examle.com/
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.(?:php|html) [NC]
RewriteRule ^ http://www.examle.com/ [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(.+)\.html$ $1.php [L,NC]
RewriteRule ^fr/(.)*$ / [R=301,NC,L]
Make sure to clear your browser cache or use a new browser for testing.

Wordpress site htaccess not redirecting to https when manually entering URL starting with http

I've made changes to my htaccess file on my WordPress site to redirect traffic from http to https.
Most cases it works fine and redirects traffic to https, but some cases it doesn't.
For example, if I try access home page with http in address it redirects to https, but if I try and access another page on the site with http in URL it stays on http:
http: //example.com redirects fine to https: //example.com
http: //example.com/page stays on http: //example.com/page
Current htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>
# END WordPress
I've tried numerous answers in other question, what else can I try?
try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Why do you have the following at the bottom? What happens when you remove this? I think this may be conflicting with RewriteCond %{HTTPS} off at the top. What happens when you remove this...
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
It will work for www and https
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Change your site address in Settings:
and add the code below at the top of WordPress’ .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
I had the same problem, and the fix was really simple... Just be sure to put the https redirection BEFORE the original rewrite code of Wordpress...
Exemple :
# Redirection code (redirect no www to www and http to https)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Redirect base URL to wp/index.php

When I open www.fimos.my, it should redirect me to www.fimos.my/wp/index.php, but I cannot get this to work correctly, this is what my htacess file looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#RewriteCond %{HTTP_HOST} ^maznia\.my$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.maznia\.my$ [OR]
#RewriteCond %{HTTP_HOST} ^www\.fimos\.my$
#RewriteRule ^/?$ "http\:\/\/fimos.my\/wp\/index\.php" [R=301,L]
#FORCE www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^fimos.my [NC]
RewriteRule ^(.*)$ "http://fimos.my/wp/index.php" [L,R=301]
This show the error cannot find the file in cpanel, they direct to link fimos.my/wp/index only.. there aren't to fimos.my/wp/index.php
This is my question:
How to redirect to www.fimos.my/wp/index.php?

how to change url structure with 301 code q2a

I have a problem with duplicate contents in search engine .
I can access a page in q2a web site using both of these url's !
http://www.domain.com/index.php?qa=1306&qa_1=title
http://www.domain.com/1306/title
I want to redirect the first one to second 1 how ca I do it ?
I tried codes in these page and other things too but none of them works :(
htaccess for changing index.php?ms=user to /user
my current htaccess is :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Redirect 301 /math/ http://math.domain.com/
</IfModule>
I used these and It seems work fine :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/?$ /index.php?qa=users [R=301,L]
RewriteRule ^tags/?$ /index.php?qa=tags [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/qa-theme/.*
RewriteCond %{REQUEST_URI} !^/qa-content/.*
RewriteCond %{REQUEST_URI} !^/analytic/.*
RewriteCond %{REQUEST_URI} !^/qa-plugin/.*
RewriteCond %{REQUEST_URI} !^/help_files/.*
RewriteRule ^(.*)/(.*)/?$ /index.php?qa=$1&qa_1=$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/qa-theme/.*
RewriteCond %{REQUEST_URI} !^/qa-content/.*
RewriteCond %{REQUEST_URI} !^/analytic/.*
RewriteCond %{REQUEST_URI} !^/qa-plugin/.*
RewriteCond %{REQUEST_URI} !^/help_files/.*
RewriteRule ^(.*)/(.*)/(.*)/?$ /index.php?qa=$1&qa_1=$2&qa_2=$3 [R=301,L]
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Redirect 301 /math/ http://math.domain.com/
</IfModule>

Apache htaccess mod rewrite

So, I am having some issues with my htacces file trying to do some re-write conditions.
What I am trying to do is:
There are multiple domains pointed to this web folder.
If the domain is anything but example.com I want it to rewrite to example.com
UNLESS - the path is /path
Everything is working now except when you go to www.otherexample.com/path
It is hitting the last rule and changing the url to http://dev.otherexample.com/index.php?qs-rewrite=path and causes a redirect loop.
Here's the entire htaccess file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} !example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/path [NC]
RewriteRule ^.*$ http://dev.example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qs-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
This should be your complete .htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/path [NC]
RewriteCond %{QUERY_STRING} !qs-rewrite=[^&]+ [NC]
RewriteRule ^ http://dev.example.com%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . /%1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php?qs-rewrite=%{REQUEST_URI} [L,QSA]
</IfModule>

Categories