Forum Moderators: phranque
RewriteCond %{REQUEST_URI} ^community [OR]
RewriteCond %{REQUEST_URI} ^admin/ [OR]
RewriteCond %{REQUEST_URI} ^administrator/ [OR]
RewriteCond %{REQUEST_URI} ^node/
RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
RewriteRule ^(.*)$ redirect.php?page=$1 [QSA,L]
What I want to do with this is to get mod_rewrite to send the request to index.php if the URL contains one of the following: community, admin, administrator or node.
If none of the above has a match, then the request will be sent to redirect.php.
This didn't work as expected. What exactly did I do wrong?
Thanks!
RewriteCond %{REQUEST_URI} ^/community [OR]
RewriteCond %{REQUEST_URI} ^/admin/ [OR]
RewriteCond %{REQUEST_URI} ^/administrator/ [OR]
RewriteCond %{REQUEST_URI} ^/node/
RewriteRule (.*) /index.php?q=$1 [L,QSA]
#
RewriteCond %{REQUEST_URI} !^/redirect\.php
RewriteRule (.*) redirect.php?page=$1 [QSA,L]
This could also be rewritten as:
RewriteCond $1 ^community [OR]
RewriteCond $1 ^admin/ [OR]
RewriteCond $1 ^administrator/ [OR]
RewriteCond $1 ^node/
RewriteRule (.*) /index.php?q=$1 [L,QSA]
#
RewriteCond $1 !^redirect\.php
RewriteRule (.*) redirect.php?page=$1 [QSA,L]
or even as:
RewriteRule ^((community¦admin/¦administrator/¦node/).*) /index.php?q=$1 [L,QSA]
#
RewriteCond $1 !^redirect\.php
RewriteRule (.*) redirect.php?page=$1 [QSA,L]
Replace all broken pipe "¦" characters with solid pipes before use; posting here modifies pipe characters.
Jim
When I enter "http://www.domain.com/community" in the address bar, it returns "http://www.domain.com/community/?q=community". I can't use "community/" with the slash due to the CMS limitation. What other option do I have without the system adding "?q=community" to my URL?
RewriteCond $1 ^community [OR]
RewriteCond $1 ^admin/ [OR]
RewriteCond $1 ^administrator/ [OR]
RewriteCond $1 ^node/
RewriteRule (.*) /index.php?q=$1 [L,QSA]
#
RewriteCond $1!^redirect\.php
RewriteRule (.*) redirect.php?page=$1 [QSA,L]
Thanks for your help again.
# Add trailing slash if trailing slash is not present and
# URI does not end with a period and filetype (e.g. .gif)
RewriteCond %{REQUEST_URI} !(\.[^/]+¦/)$
RewriteRule (.+) /$1/
#
# Rewrite specific subdirectory requests to index.php
RewriteCond $1 ^community [OR]
RewriteCond $1 ^admin/ [OR]
RewriteCond $1 ^administrator/ [OR]
RewriteCond $1 ^node/
RewriteRule (.*) /index.php?q=$1 [L,QSA]
#
# Rewrite everything else to redirect.php
RewriteCond $1 !^redirect\.php
RewriteRule (.*) redirect.php?page=$1 [QSA,L]
Also consider whether you want or need to rewrite requests for images, external stylesheets and JavaScripts, etc. Simply add exclusions similar that that already in place for /redirect\.php to prevent requests for these files from being rewritten.
Jim