Forum Moderators: phranque

Message Too Old, No Replies

Nice URL in URL rewriting

         

decola

7:08 pm on Feb 12, 2007 (gmt 0)

10+ Year Member



Hi all! I think I'm rather confuse about URL rewriting.

I use these lines in my Apache configuration file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_FILENAME}!/index.php
RewriteRule ^/(.*)$ [%{HTTP_HOST}...] [L]

Thans these lines, when I ask for:
http://www.example.com/index.php
I obtain from the server:
http://www.example.com/index.php

While when I ask for (for example):
http://www.example.com/docs/general.htm
I obtain from the server:
http://www.example.com/index.php?q=docs/general.htm

So in index.php, I can know the real requested URL.

What I want is that in the URL bar, after request, I can see
"http://www.example.com/docs/general.htm"
and not:
http://www.example.com/index.php?q=docs/general.htm

Where's the error? What I have to add to my lines?

jdMorgan

12:26 am on Feb 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simply change the syntax to specify a server-internal rewrite, instead of an external redirect:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} !/index\.php
RewriteRule ^/(.*)$ /index.php?q=$1 [L]

Jim

decola

1:41 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



It works Jim. Thank You. It was logical!

But instead of:
RewriteRule ^/(.*)$ /index.php?q=$1 [L]

I have to write the absolute path:
RewriteRule ^/(.*)$ /var/www/example.com/www.example.com/index.php?q=$1 [L]

Infact I'm managing several domains and several third level domains for each domain. And so I'm using that file system structure.

How can I specify just index.php instead of the full path?

Thanks in advance.

jdMorgan

3:27 pm on Feb 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like your DocumentRoot is not defined correctly. DocumentRoot should define the base directory for each virtual server -- specifying your "/var/www/example.com/www.example.com" path, making it unnecessary to specify this full path in each RewriteRule. You will likely have other (and possibly very serious) problems due to this as well.

Get that corrected first and then, only if necessary, use the RewriteBase directive of mod_rewrite to further refine the path.

Jim

decola

4:32 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



I'm using VirtualDocumentRoot, in a good manner, I think.

Adjust DocumentRoot seems too hard for me. Everythink seems to work good. So I'll use my workaround.

Thanks Jim.