.htaccess not ignoring a directory when applying rules - .htaccess

Stuck on this one for a while before I turned for help, any assistance is appreciated.
For all intensive purposes I had to use this method to redirect all the lowercase URLS to work on my current setup, its not pretty I know.
The issue is when I use this setup all the Urls in the directory its supposed to skip break. For example /dont-touch/File1 stops working - I need to insert the below code so the lowercase rewrites dont apply to /dont-touch
RewriteCond %{REQUEST_URI} "/dont-touch/" [OR]
RewriteCond %{REQUEST_URI} "/blog/"
RewriteRule ![A-Z] - [S=26]
RewriteRule ^(.*)A(.*)$ /$1a$2 [R,L]
RewriteRule ^(.*)B(.*)$ /$1b$2 [R,L]
RewriteRule ^(.*)C(.*)$ /$1c$2 [R,L]
RewriteRule ^(.*)D(.*)$ /$1d$2 [R,L]
RewriteRule ^(.*)E(.*)$ /$1e$2 [R,L]
RewriteRule ^(.*)F(.*)$ /$1f$2 [R,L]
RewriteRule ^(.*)G(.*)$ /$1g$2 [R,L]
RewriteRule ^(.*)H(.*)$ /$1h$2 [R,L]
RewriteRule ^(.*)I(.*)$ /$1i$2 [R,L]
RewriteRule ^(.*)J(.*)$ /$1j$2 [R,L]
RewriteRule ^(.*)K(.*)$ /$1k$2 [R,L]
RewriteRule ^(.*)L(.*)$ /$1l$2 [R,L]
RewriteRule ^(.*)M(.*)$ /$1m$2 [R,L]
RewriteRule ^(.*)N(.*)$ /$1n$2 [R,L]
RewriteRule ^(.*)O(.*)$ /$1o$2 [R,L]
RewriteRule ^(.*)P(.*)$ /$1p$2 [R,L]
RewriteRule ^(.*)Q(.*)$ /$1q$2 [R,L]
RewriteRule ^(.*)R(.*)$ /$1r$2 [R,L]
RewriteRule ^(.*)S(.*)$ /$1s$2 [R,L]
RewriteRule ^(.*)T(.*)$ /$1t$2 [R,L]
RewriteRule ^(.*)U(.*)$ /$1u$2 [R,L]
RewriteRule ^(.*)V(.*)$ /$1v$2 [R,L]
RewriteRule ^(.*)W(.*)$ /$1w$2 [R,L]
RewriteRule ^(.*)X(.*)$ /$1x$2 [R,L]
RewriteRule ^(.*)Y(.*)$ /$1y$2 [R,L]
RewriteRule ^(.*)Z(.*)$ /$1z$2 [R,L]
This is how my HTACCESS file looks, Ive tried putting it at the start... the end. Nothing works.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !/component/
RewriteCond %{REQUEST_URI} !/administrator/
RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

First, you're better of using RewriteMap here:
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
This will change everything in the URI to lowercase, instead of 26 slow rules.
Secondly, for the directories not to be rewritten, I don't think you should put them in quotes
RewriteCond %{REQUEST_URI} ^/dont-touch(/|$) [OR]
RewriteCond %{REQUEST_URI} ^/blog(/|$)
RewriteRule ^.*$ - [NC,L]
And if you put the [L] flag at the end, nothing below that point will interfere with this rule.

Related

Convert display language to subfolder with htaccess

For a website I have locally, I need to set the display language as if it were a subfolder, using an htaccess file.
For example, if I choose to display the site in German, instead of displaying it like this => local_ip/test/index.php?lang=de, I would like it to be displayed like this => local_ip/test/de/ .
Also, if I type in the url without setting the language, I would like htaccess to automatically redirect to the German language, from so => local_ip/test/tour/mountain/ to so => local_ip/test/de/tour/mountain .
My current htaccess file is structured as follows:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{QUERY_STRING} ^t=(.+?)
RewriteRule ^city/(.+?)/?$ city.php?url=$1&t=%1 [NC,L]
RewriteCond %{QUERY_STRING} ^p=([0-9]+)
RewriteRule ^city/(.+?)/?$ city.php?url=$1&p=%1 [NC,L]
RewriteCond %{QUERY_STRING} ^t=(.+?)&p=([0-9]+)
RewriteRule ^city/(.+?)/?$ city.php?url=$1&t=%1&p=%2 [NC,L]
RewriteCond %{QUERY_STRING} ^c=true
RewriteRule ^city/(.+?)/?$ city.php?url=$1&c=true [NC,L]
RewriteRule ^city/(.+?)$ city.php?url=$1 [NC,L]
RewriteRule ^tour/(.+?)$ tour.php?url=$1 [NC,L]
SOLVED
After several attempts and after reading several support requests posted in this community, I found a way to make the system recognise all the other rules as well. All I had to do was put them before the last rule provided by the user who supported me. Here is the final code.
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !/de/ [NC]
RewriteRule (.*) /test/de/$1 [R,L]
RewriteRule ^de/$ /test/index.php?lang=de [L]
RewriteCond %{QUERY_STRING} ^t=(.+?)
RewriteRule city/(.+?)/?$ city.php?url=$1&t=%1&lang=de [NC,L]
RewriteCond %{QUERY_STRING} ^p=([0-9]+)
RewriteRule city/(.+?)/?$ city.php?url=$1&p=%1&lang=de [NC,L]
RewriteCond %{QUERY_STRING} ^t=(.+?)&p=([0-9]+)
RewriteRule city/(.+?)/?$ city.php?url=$1&t=%1&p=%2&lang=de [NC,L]
RewriteCond %{QUERY_STRING} ^c=true
RewriteRule city/(.+?)/?$ city.php?url=$1&c=true&lang=de [NC,L]
RewriteRule city/(.+?)$ city.php?url=$1&lang=de [NC,L]
RewriteRule tour/(.+?)$ tour.php?url=$1&lang=de [NC,L]
RewriteRule ^de/(.*)$ /test/$1 [L]
You can use the following :
RewriteEngine on
#redirect URLs to include /de
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/de/ [NC]
RewriteRule (.*) /test/de/$1 [R,L]
# /test/index.php?lang=de to /test/de
RewriteRule ^de/$ /test/index.php?lang=de [END]
RewriteRule ^de/(.+)$ /test/$1 [END]

Rewrite gives a 404 error

I need to rewrite an url from this
https://www.domain.tld/stand-carros-usados/?brand=2&model=&category=&fuel=&kms=&price=
to this
https://www.domain.tld/stand-carros-usados/alfa-romeo
and the code is this
RewriteCond %{REQUEST_URI} ^/stand-carros-usados [NC]
RewriteCond %{QUERY_STRING} ^brand=(.*)&model=(.*)&category=(.*)&fuel=(.*)&kms=(.*)&price=(.*)
RewriteRule ^(.*)$ https://www.domain.tld/stand-carros-usados/alfa-romeo? [L]
The url is changing the one i want but its gives me a 404 page?
Anyone knows why?
EDIT
This is the .htaccess file i have. A bit messi because who created didnĀ“t care that much.
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^pt/(.*)$ http://%{HTTP_HOST}/$1 [L,R]RewriteCond %
{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^viaturas(.*)$ https://%{HTTP_HOST}/stand-carros-usados$1 [R=301,L]
RewriteRule ^automoveis(.*)$ https://%{HTTP_HOST}/stand-carros-usados$1 [R=301,L]
RewriteRule ^print/([a-zA-Z0-9_-]+)?$ ajax/printcar.php?id=$1 [L]
RewriteRule ^process-order/([a-zA-Z0-9_-]+)?$ process-order.php?h=$1 [L]
RewriteRule ^([^\.]+)?$ index.php?section=$1 [L]
RewriteRule ^eng/([^\.]+)?$ index.php?section=$2 [L]
RewriteRule ^eng?$ index.php [L]

cannot create clean url with .htaccess

I provided this .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.lebmotors.com/new/
RewriteRule (.*) http://www.lebmotors.com/new/$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ moreprod.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ moreprod.php?id=$1
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2&catid=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2&catid=$3
Still it does not work
I get: http://www.lebmotors.com/new/moreprod.php?id=107&topid=4&catid=8
What AM I doing wrong
Many Thanks
First of all, you don't need to repeat RewriteEngine On directive.
Then, when you add your rules, you still can access your pages via moreprod.php (but you can also access it from new clean url).
Here's how your htaccess should look like, assuming moreprod.php is also in new folder
Options -MultiViews
RewriteEngine On
RewriteBase /new/
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /morenews\.php\?id=([^&\s]+)\s [NC]
RewriteRule . morenews/%1/? [R=301,L]
RewriteRule ^morenews/([^/]+)/$ morenews.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3 [L]
With this code, if you try (for example) to reach http://domain.com/new/moreprod.php?id=123&topid=456&catid=789 then you'll redirect to http://domain.com/new/moreprod/123/456/789/
Conclusion
You can now access your pages via clean urls like
http://domain.com/new/moreprod/123/ (id=123)
http://domain.com/new/moreprod/123/456/ (id=123 and topid=456)
http://domain.com/new/moreprod/123/456/789/ (id=123 and topid=456 and catid=789)
Resolved, just moved these lines to the bottom of .htaccess
RewriteEngine On
RewriteBase /new/
....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
.....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/%4/? [R=301,L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
.....
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3&cagid=$4 [L]
# THIS TO THE BOTTOM
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

rewrite dynamic url

I have the following problem:
http://www.mydomain.com/articles.php?artid=89
should become: http://www.mydomain.com/mykeyword
I dont mind if the id remain in the url...like: http://www.mydomain.com/89/mykeyword
I have the following .htaccess for the moment:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
The above part works like a charm.
Any help will be deeply appreciated.
Regards, Zoran
Append these rule at the bottom of your .htaccess:
RewriteEngine On
RewriteBase /turkexpo/
RewriteCond %{HTTP_HOST} ^(webone\.gr)$ [NC]
RewriteRule ^(.*)$ http://www.%1/turkexpo/$1 [R=302,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/news\.php [NC]
RewriteRule ^ mykeyword [R=302,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/articles\.php\?artid=([0-9]+) [NC]
RewriteRule ^ %1/mykeyword? [R=302,L]
RewriteRule ^([0-9]+)/mykeyword/?$ articles.php?artid=$1 [L,NC,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+turkexpo/companies\.php\?fairid=([0-9]+)&ehallid=([0-9]+) [NC]
RewriteRule ^ companies/%1/%2? [R=302,L]
RewriteRule ^companies/([0-9]+)/([0-9]+)/?$ companies.php?fairid=$1&ehallid=$2 [L,NC,QSA]
This will forward a URI of /89/mykeyword to /articles.php?artid=89 and externally redirect the opposite of it.
Once you make sure it is working change R=302 to R=301.

What is the .htaccess/mod_rewrite solution for this redirect problem?

(Please see important Additional information edited in near the bottom of question)
I'm trying to get the following url
http://www.example.co.uk/home/templates/cnb/fb_calendar/events/view/289
to redirect to
http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:289
I thought this would work
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^home/templates/cnb/fb_calendar/events/view/([^/\.]+)?$ http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R=302,L]
but it didn't. The rule does not 'engage' at all - original url goes through unchanged. What am I doing wrong?
I'm including the whole .htaccess file below: the rule I'm talking about is the fourth one down. (The file was mostly generated by cpanel utility rather than by hand.)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^approve/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&approve\=$1" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^disapprove/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&disapprove\=$1" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^direct/([^/\.]+)/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&direct\=$1" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^home/templates/cnb/fb_calendar/events/view/([^/\.]+)?$ http://www.example.co.uk/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^uk/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=6\&Itemid\=7" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^inspirational/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=7\&Itemid\=8" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^gospel/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=1\&Itemid\=3" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^bible/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=1\&Itemid\=2" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^dab/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=14\&Itemid\=35" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/www\.example\.co\.uk\/home" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^abi/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=20\&Itemid\=37" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^anne/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=16\&Itemid\=55" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ben/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=25\&Itemid\=56" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^catherine/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=22\&Itemid\=57" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^dave/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=26\&Itemid\=53" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^jan/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=21\&Itemid\=58" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^nick/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=23\&Itemid\=60" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^paul/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=18\&Itemid\=59" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^robbie/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=17\&Itemid\=61" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^roy/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=15\&Itemid\=54" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^ruth/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=19\&Itemid\=62" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^steve/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=14\&Itemid\=64" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^trevor/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=24\&Itemid\=63" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^jobs/?$ "http\:\/\/www\.ucb\.co\.uk\/vacancies" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^prayer/?$ "http\:\/\/www\.ucb\.co\.uk\/prayer" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^yousay/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=11\&Itemid\=31" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^christmasappeal/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=12\&Itemid\=32" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^luke/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=29\&Itemid\=68" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^juls/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=blogcategory\&id\=30\&Itemid\=71" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^tv/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=5\&Itemid\=6" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^canigetdab/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=14\&Itemid\=35" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^playlist\/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_wrapper\&Itemid\=74\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^books\/?$ "http\:\/\/www\.example\.co\.uk\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^bookcase\/?$ "http\:\/\/www\.example\.co\.uk\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^donate\/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=12\&Itemid\=32\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^haiti\/?$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=560\&Itemid\=78\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^easter$ "http\:\/\/www\.example\.co\.uk\/" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^social$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=568\&Itemid\=81" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^orgs$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=8\&Itemid\=28" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^cnb$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^cnb\/login$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&login\=" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^noticeboard$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^noticeboard\/login$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=574\&Itemid\=85\&login\=" [R=302,L]
RewriteCond %{HTTP_HOST} ^example.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.co.uk$
RewriteRule ^bagofhope$ "http\:\/\/www\.ucb\.co\.uk\/bagofhope" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^mp3stream$ "http\:\/\/example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=577\&Itemid\=87" [R=302,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^posters$ "http\:\/\/www\.example\.co\.uk\/home\/index\.php\?option\=com_content\&task\=view\&id\=579\&Itemid\=88" [R=302,L]
-- Edit -- Additional information:
I've narrowed the problem down to the fb_calendar directory - if I use a directory with a random name instead of fb_calendar it works. So it must be something IN this directory that's causing the problem. There is another .htaccess file in this directory with the following contents:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Is this causing the problem? I need a rewrite rule that will not be effected by any other .htaccess files/rewrite rules in folders on the path in the URL. How can I do this?
mod_rewrite will, by default, only use directives from a single .htaccess file per (internal) request, and the .htaccess file used will be the last one found to have mod_rewrite directives down your request path.
In this case, .../fb_calendar/.htaccess exists and contains directives, so they are used instead of the directives in your root.
Furthermore, note that none of the directives are inherited automatically, so doing something like the following will generate a 404, since directives are present, but the RewriteEngine was never turned on in the second file:
/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php?here
/test/.htaccess:
RewriteRule ^ /index.php?there
Request -> http://example.com/test/non-existent-path
As it turns out, you can import rules from parent .htaccess files using the RewriteOptions directive:
RewriteEngine On
RewriteOptions inherit
Note that the parent rule set is imported after the existing rule set though, so in your case the path would be rewritten to .../fb_calendar/app/webroot/events/view/... before being processed by the rule in your root .htaccess file (and would therefore not match).
Your options in that case would be to either modify your rule to accommodate for that, or, perhaps more easily, you could just move your rule to the .../fb_calendar/.htaccess file and adjust it for being in that directory.
RewriteRule ^home/templates/cnb/fb_calendar/events/view/([^/\.]+)?$ /home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:$1 [R=302,L]
I just removed the http:// from the url it redirects to.
Works like a charm. Test it here:
http://manson.revora.net/home/templates/cnb/fb_calendar/events/view/1234
goes to
http://manson.revora.net/home/index.php?option=com_content&task=view&id=574&Itemid=85&direct=view:1234
Also, this rewrites the url in the address bar too, but since you added R=302 I take it that's what you wanted? And you don't need that first rule, as pointed out in the comments.

Resources