Forum Moderators: phranque

Message Too Old, No Replies

Removing # from end of url

Removing traling # from of url including any subdomain

         

tsarma

6:17 am on May 25, 2012 (gmt 0)

10+ Year Member



how can I rewrite
*.example.com/#

to
*.example.com

Just to remove hash '#' for example.com url including any sub domain

g1smd

6:40 am on May 25, 2012 (gmt 0)

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



You can't. The # is wholly evaluated inside the browser.

It is not sent to the server as a part of the request.

tsarma

7:22 am on May 25, 2012 (gmt 0)

10+ Year Member



Thanks for making it clear. it makes a sense. But what if I have say word "root" instead of #, how would then rewrite it.

lucy24

8:15 am on May 25, 2012 (gmt 0)

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



I think you need to ask your question in more words. I'm not clear whether you are asking about the literal strings "#" or "root", or if you mean something else.

You can't use real domain names, but you can give the rest of the path as an example. Are you now asking how to redirect "www.example.com/foobar" to "www.example.com" alone?
Or how to get rid of "index.html"?

tsarma

8:38 am on May 25, 2012 (gmt 0)

10+ Year Member



Yes I want to redirect "www.example.com/foobar" to "www.example.com" and also it should apply for all the subdomain of example.com. Like
A.example.com/foobar to A.example.com
B.example.com/foobar to B.example.com

g1smd

8:40 am on May 25, 2012 (gmt 0)

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



In htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(robots\.txt|index\.php)
RewriteRule ^(.+) http://%{HTTP_HOST}/? [R=301,L]


In httpd.conf replace
^(.+)
with
^/(.+)


No pages, images, stylesheets or files will be accessible other than robots.txt and index.php (accessed by requesting "/").

If you do need access to other stuff, change the (.+) pattern to be more specific, perhaps selecting URLs with specific extensions to redirect.

tsarma

9:23 am on May 25, 2012 (gmt 0)

10+ Year Member



Thanks a lot, In my case
RewriteCond %{REQUEST_URI} ^/root
RewriteRule ^(.+) http://%{HTTP_HOST}/? [R=301,L]

worked

lucy24

10:18 am on May 25, 2012 (gmt 0)

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



If you're only looking at one specific file, put it in the Rule and you won't need a Condition.

RewriteRule ^root http:// ... et cetera

Matter of fact, if you're not changing the host, you could even do something you normally wouldn't do:

RewriteRule ^root / [R=301,L]

The server will replace / with the existing protocol and domain, whatever they might happen to be.

g1smd

10:30 am on May 25, 2012 (gmt 0)

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



If you do that, be aware that the pattern should be
!^root
as the code is supposed to redirect all other requests.

I would caution against redirecting requests for robots.txt. Either return a valid
robots.txt
file or 404.

tsarma

2:59 pm on May 25, 2012 (gmt 0)

10+ Year Member



Thanks guys very informative