Forum Moderators: phranque
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/redirect/
RewriteRule ^[^/]+/(.*) /index.php?$1 [R,L]
When I put this in the root directory of my domain everything works fine. However, when I place it in a subdir, then it fails. What am I doing wrong? Or is it impossible what I want?
thanks in advance.
ThA WebMasteR
Welcome to WebmasterWorld [webmasterworld.com]!
For each level you go down in placing your .htaccess code, you will need to remove one directory match from your RewriteRule pattern; The URL-path 'seen' by RewriteRule is relative to the directory in which it is executed.
So, for example, if you put the .htaccess code one subdirectory down, you'll need to remove the leftmost [^/]+/ in the RewriteRule pattern:
RewriteRule (.*) /index.php?$1 [R,L]
RewriteCond %{REQUEST_URI} !/index\.php$
RewriteRule (.*) /index.php?$1 [R,L]
I am developing a CMS for myself, but I want to use it also on sites which are in a folder of the domain. Like [yourdomain.com...] When a user goes to [yourdomain.com...] the .htaccess is forced to open: [yourdomain.com...] . Do you get what I want?
The .htaccess I wrote only works when the cms is in: [yourdomain.com...] Or is it impossible what I want?
Thanks for your reply in advance!
ThA WebmasteR
If you want the script to be refernced using a relative path (relative to the directory where this .htaccess code resides), then omit the leading slash.
The key here is to know *where* the script resides, and to provide a complete or relative path to it.
Assuming the .htaccess code goes into folder "folder1"
redirecting http://yourdomain.com/folder1/folder2/cms/redirect/home to http://yourdomain.com/folder1/folder2/cms/index.php?home
your choices would be:
# "Silent" internal rewrite (browser shows original URL) using fixed local script location
RewriteRule ^folder2/cms/redirect/(.+) /folder1/folder2/cms/index.php?$1 [L]
#
# "Silent" internal rewrite (browser shows original URL) using relative local script location
RewriteRule ^folder2/cms/redirect/(.+) folder2/cms/index.php?$1 [L]
#
# External redirect (new URL shows in browser) using canonical URL (script can be on any server)
RewriteRule ^folder2/cms/redirect/(.*) http://www.yourdomain.com/folder1/folder2/cms/index.php?$1 [R=301,L]
Note that because the .htaccess code resides in /folder1, that part of the URL is stripped, and is not used in the RewriteRule pattern-matching.
Refs:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Jim
php_flag register_globals on
Options +FollowSymLinks
RewriteEngine on
RewriteBase /dev/
RewriteCond %{REQUEST_URI} !^(.+)index\.php
RewriteCond %{REQUEST_URI} !^(.+)components
RewriteCond %{REQUEST_URI} !^(.+)data
RewriteCond %{REQUEST_URI} !^(.+)images
RewriteCond %{REQUEST_URI} !^(.+)plugins
RewriteCond %{REQUEST_URI} !^(.+)templates
RewriteRule ^(.*) index.php?$1 [L]
in my cms I use encrypted URL's to go to pages. When I wnt to go to: [localhost...]
NVEkzTGpBdU1DNHh8Ym1WNGRIQnBaQT09fFgyaHZiV1U9fGFXNXNiMmRmYldWemMyRm5aUT09fFZTQnJkVzUwSUdocFpYSnZibVJ
sY2lCVmR5Qm5aV0p5ZFd0bGNuTnVZV0Z0SUdWdUlIZGhZMmgwZDI5dmNtUWdhVzRnZEdVZ2RuVnNiR1Z1TENCdmJTQnBiaUIwWlN
Cc2IyZG5aVzRnYjNBZ1pHVjZaU0J6YVhSbElRPT0=b1512
The server fails to load te page. However, if I use the following url to go to the SAME page, it doesn't fail:
[localhost...]
nh2WjJsdXxNVEkzTGpBdU1DNHh8Ym1WNGRIQnBaQT09fFgyaHZiV1U9fGFXNXNiMmRmYldWemMyRm5aUT09fFZTQnJkVzUwSUdoc
FpYSnZibVJsY2lCVmR5Qm5aV0p5ZFd0bGNuTnVZV0Z0SUdWdUlIZGhZMmgwZDI5dmNtUWdhVzRnZEdVZ2RuVnNiR1Z1TENCdmJTQ
nBiaUIwWlNCc2IyZG5aVzRnYjNBZ1pHVjZaU0J6YVhSbElRPT0=b1512
Failing in this case means a 403 Forbidden message. Could it be the problem that the url is to long?
Thanks!
[edited by: jdMorgan at 2:49 pm (utc) on June 18, 2004]
[edit reason] wrapped long lines to prevent side-scroll [/edit]
However, as I previously mentioned, you've not provided a fixed path to index.php in that RewriteRule, and that is the first thing I would experiment with in this case. Try something like this:
RewriteCond %{REQUEST_URI} !^.+(index\.php¦components¦data¦images¦plugins¦templates)
RewriteRule ^(.*) [b]/dev/[/b]index.php?$1 [L]
Jim