how to change url structure with 301 code q2a - php

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>

Related

.htaccess rewrite except some request_uri

I have a .htaccess file but it's not working as expected.
Redirect /some/dir http://www.example.com/someother/dir/29
<IfModule mod_rewrite.c>
RewriteEngine on
# HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !=/buy/confirm
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/some/dir
RewriteRule ^(.*)$ index.php?issue=$1 [L,QSA]
</IfModule>
I've been checking this with http://htaccess.mwl.be/ and I don't understand a line when I enter "http://www.example.com/buy/confirm":
RewriteCond %{REQUEST_URI} !=/buy/confirm This condition was met.
What exactly contains %{REQUEST_URI} to met the condition != /buy/confirm?? I've tried both /buy/confirm and buy/confirm and nothing.
I don't want to redirect to HTTPS if the url is buy/confirm.
Thanks!
You can use:
Redirect /some/dir http://www.example.com/someother/dir/29
<IfModule mod_rewrite.c>
RewriteEngine on
# HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/buy/confirm
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/favicon.ico
RewriteCond %{REQUEST_URI} !^/some/dir
RewriteRule ^(.*)$ index.php?issue=$1 [L,QSA]
</IfModule>
Try this:
RewriteEngine On
#redirect everything except /buy/confirm to https
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} !^\/buy\/confirm\/
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
#redirect /buy/confirm to http if it is accesed by https
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/buy\/confirm\/
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

.htaccess url changes when accessing from non www

I have this on my .htaccess
Options -SymLinksIfOwnerMatch +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
from my knowledge this will pass all the arguments to $_GET['url'] and force my url to www.
but when i access the url to
http://www.example.net/user/login
it works perfectly but when i remove the "www." the url become like this
http://www.example.net/index.php?url=user/login
# Rewrite|Redirect non-www to www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Rewrite|Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Conflicting multiple redirect rules in htaccess

I want to redirect the site ip to my site https as well as i want to redirect the non-www urls to www urls. i have written these two rules but they are conflicting. Here is my cade :
# 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]
#Redirect ip to site
RewriteCond %{HTTP_HOST} ^xx\.xx\.xxx\.xxx$
RewriteRule ^(.*)$ https://www.domain.pk/$1 [L,R=301]
#Redirect non-www to www
RewriteCond %{HTTPS_HOST} !^www\.
RewriteRule ^(.*)$ https://www.domain.pk/$1 [R=301,L]
</IfModule>
# END WordPress
Did you try this with this configuration?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^xx\.xx\.xxx\.xxx$ [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.domain.pk/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

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>

How do I redirect to a page of my site taking the trailing slash as the language parameter using .htaccess

I have this rule which is not redirecting properly:
#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]
Internally the parameter page is not getting received so the site shows the home page instead. I am not sure if I have this rule wrong or if it is just conflicting with the other rules which are working perfectly, or if it is an order problem.
All help is greatly appreciated.
Thanks in advance.
Below is the full htaccess file on the root of my site, in case you want to take a look at it.
Options +FollowSymlinks
RewriteEngine on
DirectoryIndex index.php
#Adds www to the domain
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
#redirect from www.mysite.com/es to www.mysite.com/public/index.php?lang=es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule /es$ public/index.php?lang=es [L]
#redirect from www.mysite.com/en to www.mysite.com/public/index.php?lang=en
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule /en$ public/index.php?lang=en [L]
#redirect from www.mysite.com/ to www.mysite.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(/)?$ public/index.php [L]
#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]
#redirect from www.mysite.com/page-NAME to www.mysite.com/public/index.php?page=NAME
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)$ public/index.php?page=$1 [L]
#redirect from www.mysite.com/ to www.mysite.com/public/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]
ok found the problem seems, it was indeed an order issue, this is way seems to work, hopefully this helps someone with the same issue
Options +FollowSymlinks
RewriteEngine on
DirectoryIndex index.php
#Adds www to the domain
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]
#redirect from www.mysite.com/page-NAME to www.mysite.com/public/index.php?page=NAME
RewriteRule page-(.*)$ public/index.php?page=$1 [L]
#redirect from www.mysite.com/es to www.mysite.com/public/index.php?lang=es
RewriteRule /es public/index.php?lang=es [L]
#redirect from www.mysite.com/en to www.mysite.com/public/index.php?lang=en
RewriteRule /en public/index.php?lang=en [L]
#redirect from www.mysite.com/ to www.mysite.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(/)?$ public/index.php [L]
#redirect from www.mysite.com/ to www.mysite.com/public/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

Categories