Htaccess RewriteRule add HTTP/1.1 at url end - php

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.

Related

.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]

.htaccess rewrite not working 301redirect

I have the following code in my .htaccess to rewrite the username.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?username=$1 [L]
</IfModule>
So this is the original url:
www.domain.com/profile.php?username='Mike'
Into this:
www.domain.com/Mike
Now I have another rewrite rule for www 301 redirect.
This also works great except when I'm at wwww.domain.com/Mike and I delete the 'www' and this is what I'm getting in my url:
www.domain.com/profile.php?username=Mike
My question is why im not getting the same url:(www.domain.com/Mike) after deleting 'www'?
Here is my full code in .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?username=$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]
Change order of your rules to keep 301 redirect rules before internal rewrite ones:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?username=$1 [L,QSA]

Removing index.php from URLS with .htaccess

I have an index.php controller what all URLs that aren't existing files redirect to.
The .htaccess rules I currently have look like this:
RewriteEngine On
DirectorySlash Off
# Remove Trailing Slashes
RedirectMatch 302 ^(.*)/$ $1
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=302]
# Reroute to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
What I want to do is use a 301 redirect if index.php is included in the URL.
BUT! I can't use RewriteBase or queries that start with a slash because the webapp I'm developing could be in a subfolder. So basically, I only want to rewrite for the current directory:
example.com/foo/index.php/bar/whatever should redirect to example.com/foo/bar/whatever
example.com/foo/index/bar/whatever should also redirect to example.com/foo/bar/whatever
localhost/place/foo/index.php/bar/whatever should redirect to localhost/place/foo/bar/whatever
localhost/place/foo/index/bar/whatever should also redirect to localhost/place/foo/bar/whatever
How can I accomplish this with .htaccess?
UPDATED CODE:
Everything here works EXCEPT:
index.php is not removed from anywhere in the URL.
Here's the code:
<IfModule mod_rewrite.c>
RewriteEngine On
DirectorySlash Off
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=302,L]
# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^ %1 [R=302,L]
# Reroute to index.php
#RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?cURL=/$1 [L,QSA]
</IfModule>
Not a good idea to mix mod_rewrite rules with mod_alias ones. Try this updated .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
DirectorySlash Off
# Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=302,L]
# Remove Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^ %1 [R=302,L]
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php[\s?/] [NC]
RewriteRule ^(.*?)index\.php(/.*)?/?$ /$1$2 [L,R=301,NC,NE]
# Reroute to index.php
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?cURL=/$1 [L,QSA]
</IfModule>
Make sure you have mod rewrite on on your server try
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
You can use like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

htaccess not working for www and non-www

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]

I want to redirect domain.com/index.php to domain.com

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]

Categories