Forum Moderators: phranque
[localhost...]
is displayed as shown above, but to PHP it looks like:
[localhost...]
I only need to do this on certain folders (i.e. not ... localhost/mysite/admin/ for example) and I need to take into account the fact that there may or may not already be parameters appended to the URL
I'm creating a site for multiple organisations to use, and based on the organisation, colours etc in the site will need to be different, but each organisation will be using the same pages, and the client wants the organisation shortcode in the URL.
I thought the best way to do this would be with mod_rewrite (my server is Ubuntu 9.10).
In .htaccess I have tried
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^folder1/(.*) $1&organisation=folder1 [NC,QSA]
If I browse [server...] I get a page not found error, and the htaccess debug log says:
(3) [perdir /var/www/sitename/] add path info postfix: /var/www/sitename/folder1 -> /var/www/sitename/folder1/destination.php
(3) [perdir /var/www/sitename/] strip per-dir prefix: /var/www/sitename/folder1/destination.php -> folder1/destination.php
(3) [perdir /var/www/sitename/] applying pattern '^folder1/(.*)' to uri 'folder1/destination.php'
(2) [perdir /var/www/sitename/] rewrite 'folder1/destination.php' -> 'destination.php&organisation=folder1'
(3) [perdir /var/www/sitename/] add per-dir prefix: destination.php&organisation=folder1 -> /var/www/sitename/destination.php&organisation=folder1
(2) [perdir /var/www/sitename/] strip document_root prefix: /var/www/sitename/destination.php&organisation=folder1 -> /sitename/destination.php&organisation=folder1
(1) [perdir /var/www/sitename/] internal redirect with /sitename/destination.php&organisation=folder1 [INTERNAL REDIRECT]
(3) [perdir /var/www/sitename/] strip per-dir prefix: /var/www/sitename/destination.php&organisation=folder1 -> destination.php&organisation=folder1
(3) [perdir /var/www/sitename/] applying pattern '^folder1/(.*)' to uri 'destination.php&organisation=folder1'
(1) [perdir /var/www/sitename/] pass through /var/www/sitename/destination.php&organisation=folder1
What am I doing wrong?
Many thanks in advance
Lucas
RewriteRule ^folder1/(.*)$ [b]/$1?o[/b]rganisation=folder1 [[b]QSA,L[/b]]
If you have a short list of first-level virtual "organisation" directories which *should* be rewritten, or an even shorter list of first-level 'real' directories which should *not* be rewritten, you can rewrite all of the "organisation" requests with a single rule, either including the "should be" list in the RewriteRule or RewriteCond pattern(s), or adding a negative-match RewriteCond to exclude the "should not be" URLs from being rewritten.
I'll make one more recommendation that may help over the long term: Putting all of the 'organisation' virtual folders in the top-level directory risks a long-term maintenance nightmare, and also risks 'collisions' between future organisation names and required site infrastructure folder names. If the number of 'organisations' grows too large, then it could even affect server performance. It is generally better to use a hierarchical approach, and put all 'organisations' into a top-level (virtual, in this case) folder, such as "/orgs/<organisation>" instead of putting all virtual "/<organisation>" folders in the root.
Using a hierarchical approach can also lead to better efficiency, as only one simple rule (testing for "^orgs/(.*)$") is needed in the top-level .htaccess file, and any 'details' related to rewriting the individual virtual directories can be handled in a separate /orgs/.htaccess file.
Jim
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^folder1/(.*)$ /$1?organisation=folder1 [QSA,L]
I still get a 404 error, and the rewrite log says:
(3) [perdir /var/www/sitename/] add path info postfix: /var/www/sitename/folder1 -> /var/www/sitename/folder1/destination.php
(3) [perdir /var/www/sitename/] strip per-dir prefix: /var/www/sitename/folder1/destination.php -> folder1/destination.php
(3) [perdir /var/www/sitename/] applying pattern '^folder1/(.*)$' to uri 'folder1/destination.php'
(2) [perdir /var/www/sitename/] rewrite 'folder1/destination.php' -> '/destination.php?organisation=folder1'
(3) split uri=/destination.php?organisation=folder1 -> uri=/destination.php, args=organisation=folder1
(1) [perdir /var/www/sitename/] internal redirect with /destination.php [INTERNAL REDIRECT]
My internal server is Ubuntu 9.10 and I'm viewing the page with Chrome on a Mac.
It DOES work however, if I use
RewriteRule ^folder1/(.*)$ $1?organisation=folder1 [QSA,L]
Cheers
To ignore this will make the job harder to do in the first place and will cause multiple problems in years to come. It will be a difficult site to maintain.
What the client 'wants' and what the best technical solution is, might be two separate things.
I'd ask the client if they want pretty URLs on a slow and unresponsive site (and do note that Google looks at page load times now) that will be difficult to maintain, or a technically robust solution with faster loading pages, while still using simple-ish URLs.