Link to home
Start Free TrialLog in
Avatar of Kosta
Kosta

asked on

Simple rewrite rule

Hello.

Please help me to configure a simple mod-rewrite rewrite rule.
I have a folder, named "pyramide" in my httpdocs folder, where my site files are. So the site is reachable by this url: http://example.com/pyramide/ .
I can not move my site physically one level up because of some technical reasons. But I need it to be reachable by the domain root: http://example.com/

Thank you.
Avatar of Bernard Savonet
Bernard Savonet
Flag of France image

I assume that you cannot move the site one level up, but that you have access to the root directory.

When someone reaches your site at http://example.com/ you want that this is translated as http://example.com/pyramide/

You can do that in 2 ways:
1 - create an Apache mod-rewrite within and .htaccess file
2 - create a php rewrite within index.php (I assume you have php since you post in tyhe php area)


The basic expression for 1 would be
Redirect 301 ^http://example.com$ http://example.com/pyramide/

The basic expression for 2 would be a file index.php containing just
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://example.com/pyramide/");
exit;
?>


Avatar of Kosta
Kosta

ASKER

Hello Fibo.

Thank you very much for the reply, but I think I did not explain my question clear enough. I don't want to redirect visitors, I want to rewrite the url, so for example if the visitor types this address: http://example.com/foo/bar/", I want him to continue to see this address in his browser's address bar, but I want him to see a content of http://example.com/pyramide/foo/bar/. I was told this is possible by using the Apache's mod-rewrite directive in a .htaccess file. But I can not figure out how exactly to set it up.

Thank you.
Kosta.
Hmmm... it is not really possible.

What would be possible (but don't do it): create a frame so that the visitors don't see that they are at some othe page. Don't do it, because it is really a problem for search engines an navigation

If you are on a page, this is the address that would be displayed by the browser... otherwise phishing would be lots easier!
You can ask Apache to redirect to some other page, but which one will be visible.
Avatar of Kosta

ASKER

But many sites now use so called Human Readable URLs technique, and it is usually based on a mod-rewrite Apache module. What it does is rewriting addresses like http://example.com/index.php?catalog=foo&article=bar to be seen in a browser as http://example.com/foo/bar/ or http://example.com/catalog/foo/article/bar/
I thought I need something similar, even much simpler...
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that the rule must be in your server's document root .htaccess file, or in the server config.  This will not work if it is placed in the sub-directory's .htaccess file.