redirect url containing “%20” or space at end of it .htacess

you can use the below given redirect rule in your .htacess file.

redirect 301 “/about-us ” http://www.avidindiainc.com/about-us

the above one worked for me

Advertisements

Redirect through .htaccess file

Here’ s the logic to redirect particular page through .htaccess file.

RewriteCond %{HTTP_HOST} ^avidindiainc.com [NC]
RewriteRule ^(.*)$ http://www.avidindiainc.com/$1 [L,R=301]

as given above,
here avidindiainc.com is the url of the site you want to redirect. here if the url typed in the address bar is http://avidindiainc.com, it will redirect to http://www.avidindiainc.com.

the above given logic will work for apache webserver only as .htaccess file is supported by apache webserver and not IIS webserver. In case you have an IIS webserver here’s something you can do.

But this logic has to be written in php file. The logic follows as below:

<?php

if($_SERVER[‘SERVER_SOFTWARE’]==’Microsoft-IIS/6.0′){
if($_SERVER[‘HTTP_HOST’]!=’www.theartel.com’){
header( “HTTP/1.1 301 Moved Permanently” );
if($_SERVER[‘argv’])
header( “Location: http://www.&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’].’?’.@implode(‘&’,$_SERVER[‘argv’]));
else
header( “Location: http://www.&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’]);
}
}


?>

thanks,

Sachin

Creating virtual host on apache, php

You can create a virtual host on your local system or your sever. i.e. you can have http://trial/ instead of http://localhost/trial/ where trial is the name of the directory that contains the website.

Here are the steps for creating virtual host on your sever:

1) open the host file and edit it as follows:

the host file is found at C:\WINDOWS\system32\drivers\etc\hosts for windows

open the file and add the following code to the bottom of the file on a new line

192.168.6.181       trial

2) Now open the httpd.conf file under the apache/bin/conf/ directory

and add the following code :  # Virtual hosts
Include conf/extra/httpd-vhosts.conf

or if already present then please uncomment the following line
: Include conf/extra/httpd-vhosts.conf

i.e. remove the # from the front of the line

3) Open apache/bin/conf/extra/httpd-vhosts.conf file

if not present create directory extra under
apache/bin/conf/

and create a file httpd-vhosts.conf file

and add this code to the file:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn’t need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/&gt;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option ‘-S’ to verify your virtual host
# configuration.
<Directory D:/wamp/www/vhosts>
Order Deny,Allow
Allow from all
</Directory>
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.localhost
#    DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost”
#    ServerName dummy-host.localhost
#    ServerAlias http://www.dummy-host.localhost
#    ErrorLog “logs/dummy-host.localhost-error.log”
#    CustomLog “logs/dummy-host.localhost-access.log” common
#</VirtualHost>

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.localhost
#    DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost”
#    ServerName dummy-host2.localhost
#    ErrorLog “logs/dummy-host2.localhost-error.log”
#    CustomLog “logs/dummy-host2.localhost-access.log” common
#</VirtualHost>

<VirtualHost *:80>
DocumentRoot D:/wamp/www
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot D:/wamp/www/vhosts/trial
ServerName trial
</VirtualHost>

if the file is present then please add the following lines at the bottom of the file

<VirtualHost *:80>
DocumentRoot D:/wamp/www
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot D:/wamp/www/vhosts/trial
ServerName trial
</VirtualHost>

4) restart your apache services and just type http://trial/ into the address bar of your browser and it will work

If you face any problem with this please feel free to contact me. I’ll try to resolve your problem as soon as possible.

Thanks,

Sachin (samsami2um@gmail.com)