Rewrite Problem!

New to mod_rewrite? This is a good place to start.

Rewrite Problem!

Postby raulk » Mon Sep 21, 2009 6:54 am

Hi!
We have a large escale webhosting and we have a segmented in hierarchical estructure
example..
/a/b/abantive translated to /abantive
/z/0/z0ero translated to /z0ero
/w/-/w-oot translated to /w-oot
/r/_/r_linux translated to /r_linux


anyone knows how to do this?
Thanks!
raulk
 
Posts: 7
Joined: Mon Sep 21, 2009 5:14 am

Postby richardk » Mon Sep 21, 2009 10:35 am

Which URL will the user visit?
Which is the working URL?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.)(.).*$ /$1/$2/$0 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby raulk » Mon Sep 21, 2009 11:09 am

Users access..

/a/b/abantive/ translated to /abantive/
/a/b/abantive translated to /abantive/
/a/b/abantive/index.php translated to /abantive/index.php
/z/0/z0ero/peep.pdf translated to /z0ero/peep.pdf

your code work's fine! but..
/pepe gets translated into /p/e/pepe
/pepe/ gets translated into /pepe/ >> OK
so when there is a slash at the end, the real path get´s hidden

what whould it be needed to add in order to allways hide the url ? not only when there is a slash at the end of it

Thanks!
raulk
 
Posts: 7
Joined: Mon Sep 21, 2009 5:14 am

Postby richardk » Tue Sep 22, 2009 9:17 am

Users access..

/a/b/abantive/ translated to /abantive/
/a/b/abantive translated to /abantive/
/a/b/abantive/index.php translated to /abantive/index.php
/z/0/z0ero/peep.pdf translated to /z0ero/peep.pdf

your code work's fine!

If my code works fine, the users access /abantive/ (the URL in the address bar of your browser) and mod_rewrite rewrites it to /a/b/abantive/.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1/$2/$0/ -d
RewriteRule ^.*.[^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.)(.).*$ /$1/$2/$0 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby raulk » Tue Oct 13, 2009 8:34 am

Hi!
if no end slash the url not'w works.. the url show /a/b/abc123
if end slash /abc123/

any idea?
raulk
 
Posts: 7
Joined: Mon Sep 21, 2009 5:14 am

Postby richardk » Tue Oct 13, 2009 2:39 pm

Replace
Code: Select all
RewriteCond %{DOCUMENT_ROOT}/$1/$2/$0/ -d
RewriteRule ^.*.[^/]$ %{REQUEST_URI}/ [R=301,L]

with
Code: Select all
RewriteCond %{REQUEST_URI} ^/(.)(.).*$
RewriteCond %{DOCUMENT_ROOT}/%1/%2%0/ -d
RewriteRule ^.*.[^/]$ %{REQUEST_URI}/ [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby raulk » Wed Oct 14, 2009 9:25 am

now the url is ok translated the folder and the folder whitch slash to the subfolders.
dom.com/abc123 -> dom.com/abc123/ (internal /a/b/abc123 but.. the html/jpg/gif etc or other files get a ERROR 404: Not Found. response.
raulk
 
Posts: 7
Joined: Mon Sep 21, 2009 5:14 am

Postby raulk » Wed Oct 14, 2009 9:56 am

sorry! :D your code works fine , only response a 500 internal server error when directory/file no exists
raulk
 
Posts: 7
Joined: Mon Sep 21, 2009 5:14 am

Postby richardk » Wed Oct 14, 2009 2:27 pm

You should get a 404 error not a 500 error. Do you really get a 500 error?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby raulk » Wed Oct 14, 2009 6:06 pm

yes we obtain a 500 internal server error , not a 404 not found..
raulk
 
Posts: 7
Joined: Mon Sep 21, 2009 5:14 am

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests

cron