Forum Moderators: phranque
Then I have created this rule:
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^(index\.php)?$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
But this is working just for index.php, because I tried
RewriteRule ^(.*)?$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1 but it does not work.
for example:
1. example.com/index.php?siteid=yyy --> example.com/cookie.php?siteid=yyy
2. example.com/something.html?siteid=yyy --> example.com/cookie.php?siteid=yyy
3. example.com/other.htm?siteid=yyy --> example.com/cookie.php?siteid=yyy
And for that cases these rules are working:
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^(.*)\.(htm¦html)$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^/(.*)\.php$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
But when I need do it for a directoy, example:
1. example.com/dir1/index.php?siteid=yyy --> example.com/cookie.php?siteid=yyy
2. example.com/dir2/something.html?siteid=yyy --> example.com/cookie.php?siteid=yyy
3. example.com/dir3/dir4/other.htm?siteid=yyy --> example.com/cookie.php?siteid=yyy
I use this rule:
RewriteRule ^/(.*)/(.*)\.(htm¦html)$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1 [R=301,L]
but, it does not work, do not nothing.
Thanks!
You can accommodate any number of directory-levels (including zero) and improve the efficiency of your codde like this:
RewriteCond %{QUERY_STRING} siteid=
RewriteRule ^(([^/]+/)*[^.]+\.(html?¦php))$ http://example.com/cookie.php?host=%{HTTP_HOST}$1 [QSA,L]
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^(.*)\.html?$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^(index\.php)?$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
The second one, is the answer to g1smd.
I don't know exactly why this do not work using just one rule and adding the php, for example:
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^(.*)\.(html?¦php)$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
I get this error: Internal Server Error 500
But, about the directories thing, i cannot do that? redirect from any directory to one root file?
Thanks
RewriteRule ^(([^/]+/)*[^.]+\.(html?¦php))$ http://example.com/cookie.php?host=%{HTTP_HOST}$1 [QSA,L]
That is for any directory level, just was to optimal to see it the first time, anyway i can't continue if a simple rule like this:
RewriteCond %{QUERY_STRING} siteid=(.*)$
RewriteRule ^(.)+\.php$ http://example.com/cookie.php?host=%{HTTP_HOST}%{REQUEST_URI}&siteid=%1
do not redirect for any php file, even I have a rule for html and htm files working, do I have some specific configuration for php files?
Thanks again
^(?:.++(?<=\.html¦\.htm))?$ You'll have to replace the ¦ pipe with solid ones since the latin1 character 7C is replaced with A6 when posting to this forum.
^(?:................)?$ .++(?<=\.html¦\.htm)