Forum Moderators: phranque
i'm having a mod_rewrite issue: i would like that
/projects/touch redirects to /projects/touch/
but so far i get erratic results: here is the htaccess file:
RewriteRule ^([A-Za-z0-9-]+)$ $1/ [R]
RewriteRule ^([A-Za-z0-9-]+)/$ myapp.php?section=$1 [L]
what happens is, if i try this:
http://example.com/projects
i get to this:
http://example.com/var/www/my-domain/domains/m2.my-domain.com/public_html/projects/
so it appends the DOCUMENT_ROOT to the url ...
strange no?
Thanks for any insight!
Alex
[edited by: jdMorgan at 3:50 pm (utc) on Jan. 23, 2008]
[edit reason] example.com [/edit]
it works for my example, but i have other rewrite and the same issue arises, but adding the L flag does not solve it this time, same happens, the document_root gets inserted in the path
here is my updated htaccess:
Options +FollowSymlinks
RewriteEngine on
# FOUR PARAMS
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ $1/$2/$3/$4/ [R=301,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ app.php?section=$1&sortBy=$2&dsAnchor=$3&item=$4
#
# TWO PARAMS
RewriteRule ^projects/([A-Za-z0-9-]+)$ projects/$1/ [R=301,L]
RewriteRule ^projects/([A-Za-z0-9-]+)/$ app.php?section=projects&sortBy=time&dsAnchor=%{TIME_YEAR}&item=$1
#
# ONE PARAM
RewriteRule ^/([A-Za-z0-9-]+)$ /$1/ [R=301,L]
RewriteRule ^([A-Za-z0-9-]+)/$ metalab2.php?section=$1 [L]
#--------------------------------------------
Note also that although the 'disposition' of this bug says that it will be fixed in Apache 2.x, my testing indicates that it still exists in Apache2.
Also, I suggest that you always use a canonical form for the substitution URL when coding an external redirect, as in:
RewriteRule ^([a-z0-9-]+)$ http://www.example.com/$1/ [NC,R=301,L]
Jim
# If URL-path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.¦/$)
# Externally redirect to add a trailing slash
RewriteRule (.*) http://www.example.com/$1/ [R=301,L]
# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ http://www.example.com/$1/ [NC,R=301,L]
Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe characters.
Jim
Indeed, now it works but i'm stumbling on another caveat: i 'm using some javascript that was analysing the urls for the pair variable=value and triggering different animations out of it.
because of url_rewrite,this does not work anymore, unfortunately. Right now i'm thinking i could maybe recompose the ugly urls via javascript before parsing, yet it's problematic because i don't know in advance how many variables will be used.
Do you know of any clever way to deal with that? maybe have php write the dynamic ugl url inside the generated html and retrieve that value in javascript?
# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ http://www.example.com/$1/ [NC,R=301,L] also, is there a way to obtain in one line all the query variables, each in its $index?
Apologies if i'm asking stupid questions: i have to catch up on regex at the same time, and your advises are super helpful.