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]
Related
I have next config in htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
it works well if I type example.com or http://example.com it redirect correctly to https://example.com, but if I type example.com/section it redirect to https://example.com/index.php which is not correct, how to fix this?
Adding the "/$1**" after index.php on this part of htaccess file then we get https://example.com/index.php/subroute, which redirects correctly to the sub route BUT STIL SHOWING INDEX.PHP in the URL
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php**/$1** [L]
This is the code I use to redirect to HTTPS for Laravel:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Force non-www:
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Force SSL redirect:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
i fixed my issue by using bellow code you can Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ example.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I need this url:
www.99bankinfo.in/index.php?bank=AxisBank
to
www.99bankinfo.in/AxisBank
but it appears this:
www.99bankinfo.in/AxisBank%20HTTP/1.1/
My .htaccess Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&]+)
RewriteRule ^ /%2/? [L,R=301]
Kindly suggest any solution, i am stucked for days...
Thanks in advance.
You need to tweak regex in last redirect rule:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&\s]+)
RewriteRule ^ /%2/? [L,R=301]
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Also keep redirect rules before rewrite ones.
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>
i'm trying to redirect www.site.ru and site.ru to www.site.ru/ru_RU. But i can't make it work.
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.ru$ [NC]
RewriteRule ^(.*)$ http://www.site.ru/ru_RU [L,R]
RewriteCond %{HTTP_HOST} ^www\.site\.ru$ [NC]
RewriteRule ^(.*)$ http://www.site.ru/ru_RU [L,R]
RewriteCond %{REQUEST_URI} ^/news
RewriteRule (.*) /news [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
It's not redirecting WWW version. Can someone tell me how to make that request. By the way, sometimes i come to situation, where in firefox it's working, but in IE it's not.
Try this code:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?site\.ru$ [NC]
RewriteRule ^$ http://www.site.ru/ru_RU [L,R]
## WHAT IS THIS RULE DOING??
# RewriteCond %{REQUEST_URI} ^/news
# RewriteRule ^ /news [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
</IfModule>
btw I had to comment out suspicious looking 2nd rule for /news. If you can explain what you're trying to do with this I can suggest you how to fix it.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ru_RU [R=permanent,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/ru_RU [R=301,L]
How to redirect mydomainname.com/index.php to mydomainname.com
Currently I use following codes also.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^mydomianname\.com
RewriteRule (.*) http://mydomianname.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule>
This should be your complete .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^mydomianname\.com
RewriteRule (.*) http://mydomianname.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule>
This example only works for http, but should roughly do the trick.
# Redirect requests with index.php to the corresponding request
# without the index.php
RewriteRule ^index.php(.*) http://mydomianname.com$1 [R=301,L]