Welcome to WebmasterWorld Guest from 107.20.34.173

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Apache mod rewrite

mod_rewrite

     

ac1982

6:52 am on Aug 28, 2012 (gmt 0)

5+ Year Member



Hi, I need your help on the following. I need to modify the apache conf and the .htaccess to make the URL from:

http://255.255.255.255/~account/


to

http://255.255.255.255/


thanks in advance

ac1982

8:02 am on Aug 28, 2012 (gmt 0)

5+ Year Member



In addition to the above I did the below test to see if mod_rewrite is working with no success.

#1 .htaccess, RewriteRule is disabled

RewriteEngine on
#RewriteRule ^alice\.html$ bob.html

Links:

http://255.255.255.255/~account/alice.html [Ok]
http://255.255.255.255/~account/bob.html [Ok]


#2 .htaccess, RewriteRule is enabled

RewriteEngine on
RewriteRule ^alice\.html$ bob.html

Links:

http://255.255.255.255/~account/alice.html [404 Not Found]
http://255.255.255.255/~account/bob.html [Ok]

ac1982

9:06 am on Aug 28, 2012 (gmt 0)

5+ Year Member



any comments will be much appreciated

MinosTheNinth

9:33 am on Aug 28, 2012 (gmt 0)



I am sorry for very quick reply, but now I'm a bit in hurry. Anyway hope, this will help you.

With rule ^alice\.html$ bob.html you say, that everything that only exact "alice.html" is rewriten.

The ^ character marks start of tested URI and $ marks end.

Try exclude ^ character from rule and it should work as you expected.

ac1982

11:01 am on Aug 28, 2012 (gmt 0)

5+ Year Member



thanks for reply I found out that the issue was the RewriteBase. Also what about my initial post to set apache conf and the .htaccess can anyone help me with that?

MinosTheNinth

3:18 pm on Aug 28, 2012 (gmt 0)



RewriteRule ^/~account([/]?)$ / [R=301,L]

This rule will redirect anyone who will try to access /~account or /~account/ to root folder of your webpage.

"R" means redirection - the browser is sent to new address and it also change URL in URL bar. The 301 code means, that this is permanent redirection. If it is not permanent redirection, then use code 302.

Hope this will help.

ac1982

4:50 pm on Aug 28, 2012 (gmt 0)

5+ Year Member



at the moment the only way to access my site is by typing:

http://www.domain.com/~account_name/public/


what i need is to access it without typing the account_name:

http://www.domain.com/public/


thank u

lucy24

5:40 pm on Aug 28, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



I need to modify the apache conf and the .htaccess

No, you don't. One or the other. If you have access to the config file, use it. Anything directory-specific goes in a <Directory> envelope. At most, allow htaccess for trivial things like indexing (overrides Indexes and/or Options). If you don't have access to the config file, you've no choice but to use htaccess.

at the moment the only way to access my site is by typing:

http://www.example.com/~account_name/public/

what i need is to access it without typing the account_name:

http://www.example.com/public/


:: please stop here and detour to the post about using example.com since Our Moderator went to the trouble of writing it and examples won't work with anything else ::

Is yours the only account name in the domain? Did there use to be more of them and you've now got rid of the others? Does the content live inside the /~account_name/ directory? Are there directories other than /public/ ?

So far I can't figure out whether you need a Redirect or a Rewrite, and whether you've got an internal problem or a DNS one.

ac1982

6:37 am on Aug 29, 2012 (gmt 0)

5+ Year Member



I am truly sorry if I have confused you, let me try explain again as simple as I can:

I have created a new account in WHM/CPanel with a dedicated IP.
And to access that account files I need to
http://<dedicated_ip>/~account_name/

Then I changed in my domain registrant, so my domain points to the new dedicated IP.
I checked after a a couple of hours and when I typed
 www.mydomain.com

I am redirected to
 http://www.mydomain.com/cgi-sys/defaultwebpage.cgi 
for some unknown reason for me, but when i type
 http://www.mydomain.com/~account_name/
my website is shown.

So what I am trying to achieve is when a visitor goes to
www.mydomain.com 
to view the website that is in
http://www.mydomain.com/~account_name/
without the need to add ~account_name at the end of the URL neither been redirected to cgi-sys page.

I hope its more clear now. :|

[edited by: ac1982 at 6:51 am (utc) on Aug 29, 2012]

g1smd

6:48 am on Aug 29, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Your URL examples are unreadable.

Please use example.com in this forum to suppress URL auto-linking.

ac1982

6:52 am on Aug 29, 2012 (gmt 0)

5+ Year Member



sorry please check again I have updated my post

lucy24

8:13 pm on Aug 29, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



I checked after a a couple of hours and when I typed www.example.com
I am redirected to http://www.example.com/cgi-sys/defaultwebpage.cgi for some unknown reason for me

Do you mean that your address bar changes? What is the content of the page you end up at? It looks like the default starter page for some CMS-- in other words, not necessarily a mistake.

but when i type http://www.example.com/~account_name/ my website is shown.

Again, does the address bar change?

It sounds as if something got mixed up when you were updating the DNS information, assuming that's what you meant by "changed in my domain registrant". And assuming you really meant "changed IN", not simply "changed".

First step: test with a tool such as Firefox LiveHeaders. (Other browsers probably have equivalents by now.) This will show you exactly what is happening.

Also: look at your raw logs. Each redirect will be visible as a 301. Unfortunately the logs will not say what the redirect points to-- but if it is a human visitor (including yourself) the 301 will be followed by a fresh request for a different URL. Browsers go where they are told to go.

It's no use asking what to do until everyone knows exactly what's happening right now. Otherwise you risk creating an even bigger mess.

ac1982

6:14 am on Aug 30, 2012 (gmt 0)

5+ Year Member



When I typed www.example.com I am redirected to http://www.example.com/cgi-sys/defaultwebpage.cgi. How can I change the configuration to load http://www.example.com/~account_name/ instead?

lucy24

5:34 pm on Aug 30, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



First you need to find the place that sends you to /cgi-sys/defaultwebpage.cgi

Start with the DirectoryIndex section. You may have a leftover directive from a CMS you're no longer using. Then study the rest of the htaccess. I'm assuming you don't have access to the config file itself.

If you can't find anything, see what happens if you temporarily disable the htaccess file. Either delete it (KEEP A COPY!) or rename it to something like "foobar" --no leading dot, make up a silly name-- that a robot is not going to guess within your two minutes of testing. If the redirect goes away, it was in your htaccess somewhere. If not, it's either in the config file or you've got more than one htaccess to keep track of.

You can't simply add a redirect, or you risk going around in circles. Or, at best, getting multiple redirects on every request.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month