Forum Moderators: phranque

Message Too Old, No Replies

Show domain name in address bar

Domain name only in address bar

         

nam12

5:07 pm on Mar 5, 2010 (gmt 0)

10+ Year Member



Hi, I want to display only the domain name in the address bar, like - "http://www.xyz.com/" instead of "http://www.xyz.com/beta/web/index.php".
I tried putting this code in .htaccess file and this does not seem to work. Any ideas on this ?
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^www.xyz.com/?$www.xyz.com/beta/web/index.php [NC,L]

g1smd

12:42 am on Mar 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you wanting every page of the site to display that way, or just one page?

If it is every page, then what you want to do, isn't really possible unless you put your whole website inside a frame... but that is SEO suicide.

If you want visitors to use a particular URL, then that is the URL you need to link to and the URL they need to click on to access that content.

You also need a rewrite and a redirect to make this work. The rewrite takes the new URL request and rewrites to an internal file path. The redirect takes a URL request with parameters and redirects to the new URL.

Your code above contains a domain name in the target and is therefore acting as a redirect (instead of a rewrite). It redirects in the wrong direction. It is exactly backwards.

nam12

1:16 am on Mar 6, 2010 (gmt 0)

10+ Year Member



Thanks for the reply.I need to do this only on the index page, not all pages of the site.

Even if the user types www.xyz.com/beta/web/index.php in the address bar, it should be changed to www.xyz.com/. But, the index.php file is in the path "beta/web/".
Should I use <a href = "www.xyz.com/"> wherever the link is used ?
My code above does not redirect. The url in the address bar still shows www.xyz.com/beta/web.index.php even if i use the rewrite in .htaccess file. I'm sorry if im being dumb, but I'm absolutely new to this. Please throw more light on this.

jdMorgan

2:29 am on Mar 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your links' source code should read '<a href="http://www.example.com/">'. Your rule won't work properly because the syntax is wrong and there is no protocol specified in the RewriteRule substitution URL.

You'll need something like this:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine on
#
# Externally redirect direct client requests for /beta/web/index.php back to "/" in root
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /beta/web/index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^beta/web/index\.php$ http://www.example.com/? [R=301,L]
#
# Additional external redirects (such as your domain canonicalization redirect, if any) go here
# ...
#
# Internally rewrite requests for URL-path "/" to /beta/web/index.php filepath
RewriteRule ^$ /beta/web/index.php [L]

Jim

nam12

9:21 pm on Mar 10, 2010 (gmt 0)

10+ Year Member



I tried your code, but still it does not work. My index.php file is in a web folder. The web folder also contains a folder downloads and this contains the .htaccess file. When I type www.example.com/beta/web/index.php, it should be replaced with www.example.com/. I also tried typing www.example.com/ and it gets replaced with www.example.com/beta/web/index.php. In any way, the url remains like that. Where am I doing the mistake ?

g1smd

9:25 pm on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code above should work as originally documented, as long as it is posted to the .htaccess file in the root of the site.


What you describe is exactly backwards. Did you use the code 'as posted' or did you modify it in any way? Are there any other .htacess files within the site? What is inside those?

nam12

10:34 pm on Mar 10, 2010 (gmt 0)

10+ Year Member



I have 3 .htaccess files. The web folder contains all php files for the site. In this, there are 2 .htaccess files. One is in a folder called connected_registerable and another is in a folder, unconnected_registerable. The third one is outside the web folder. I used the code as posted in the .htaccess files which are in web folder. These files contain AddType application/cab .cab. I added code after this.

jdMorgan

1:41 am on Mar 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code cannot work in any location other than root, because that is where you want the "home page URL" to point to. When a request arrives for "/", the .htaccess code above will rewrite that request to your index.php file in your /beta/web folder. If a client directly requests /beta/web/index.php, it will be redirected back to example.com/.

Jim

nam12

6:23 am on Mar 11, 2010 (gmt 0)

10+ Year Member



Thank you very much for the help. I will try creating a .htaccess file in root and test it.