mod_rewrite does not trigger css to load - css

I want to redirect all requests to index.php and any %{REQUEST_URI} portion should be passed as an argument to index.php. Also, even if the %{REQUEST_URI} portion points to an existing file/directory, I still want to do the redirect. For example, there is a directory called js in my document root. When I access my site like http://www.example.com/js, then I still want to redirect to http://www.example.com/index.php?uri=js instead of displaying the content of the directory in a browser.
So, I added the following two lines in my .htaccess file.
RewriteEngine On
RewriteRule .* index.php?uri=%{REQUEST_URI} [QSA]
But this does not work.
First, when I specify a path to an existing file, e.g. http://www.example.com/foo.css, it still displays a content of the file in a browser. (What I want is http://www.example.com/index.php?uri=foo.css) Second, when accessing a directory, e.g. http://www.example.com/js, then the redirect happens, but css fails to take effect and my site looks corrupted.
The good news is it works fine if I specify an arbitrary string that does not point to any files/directories in the root. I spent hours trying to debug this, but I have no clue. How would I solve my problems?
FYI, I'm using Apache 2.4.3.

Maybe this following code :
RewriteEngine On
RewriteRule ^index.php?uri=(.*)$ $1 [L]
I don't know if it's that you want.

Related

Page not found error when using plus"+" sign in the path aliases

I am trying to create a new simple node with url alias as test+node. when i save the node the page is not showing the node, the url changes as
http://server/packets/test%2Bnode
but it only shows the following error
Page not found
The requested page "/packets/test%2Bnode" could not be found.
Can anyone help me to fix this issue out...
Drupal want's to stop the "+" character from being a space. Drupal encodes the character and can't recognize the URL alias.
See this thread here:
https://drupal.stackexchange.com/questions/125156/page-not-found-error-when-using-plus-sign-in-the-url-alias
Its probably better to avoid using characters like "+" in aliases,
but maybe try adding this to your .htaccess file, with clean URL's enabled:
RewriteEngine On
RewriteCond %{THE_REQUEST} %2B
RewriteRule ^(.+)$ %{REQUEST_URI} [R=301,L,QSA,NE]

Limit web folder access to specific URL

I am hosting two different websites using one hosting package.
My initial website is self-built and runs from the public_html directory of my host let's call this 'http://www.website1.co.uk'
I also have a Word Press blog running in a folder under the public_html - so '/folder_2', let's call this 'http://www.website2.co.uk' - this URL currently points to '/folder_2' and will load the blog when entered in to a browser.
At the moment the blog is also accessible by entering 'http://www.website1.co.uk/folder_2/'.
I would like to be able to limit access to 'folder_2' to just 'website2.co.uk' - preventing somebody typing in the 'website1.co.uk/folder_2' path and being able to view the blog.
What's the best way to achieve this, bearing in mind the folder in question is running a Word Press blog.
Try adding this in your .htaccess file in folder_2
RewriteEngine On
RewriteCond %{http_host} !website2.co.uk
RewriteRule .* http://website2.co.uk
that would redirect anyone who goes to website1.co.uk/folder_2 to website2.co.uk, but if you just want them hit a 404 put this in .htaccess instead
RewriteEngine On
RewriteCond %{http_host} !website2.co.uk
RewriteRule .* - [R=404,L]
1# move folder_2 out of public_html(you really should do that).
2# rewrite all request of 'http://www.website1.co.uk/folder_2/' to 404 in htaccess
Check below link:
Redirection Subfolder Htaccess

Rewrite Drupal files directory to sub folder

I am 'merging' two Drupal sites into one multisite installation. But one of the sites has the files saved at <drupal root>/files while the other one saves them at <drupal root>/files/site-2 (which actually is a symlink to <drupal root>/sites/site-2/files). Now I'm looking for a way to 'merge' them without loosing the url structure of my site-1, i.e. I want
http://site-1.com/files to display http://site-1/files/site-1
and keep http://site-2.com/files/site-2 as it was.
I imagine that this can be done through a simple .htaccess mod_rewrite operation, but I don't know much about that. I was trying
RewriteCond %{HTTP_HOST} site-1.com
RewriteRule ^/files(.*)?$ /files/site-1$1 [NC]
but that doesn't seem to work. Could somebody help me?
Classic: The server configuration wasn't correct so that the directives didn't work. Grrr. My solution is now like I said in my first 'answer': Change the paths to use the sub directory and then redirect old files to that folder:
RewriteCond %{HTTP_HOST} site-1.com
RewriteCond %{REQUEST_URI} !^/files/site-1/.*$
RewriteRule ^files/(.*)$ /files/site-1/$1 [L,R=301]
I think internal Drupal paths don't work with rewrites (for example imagecache). That's why I chose this option.
fyi: The replace stuff I used to change the paths in the database is this (in phpmyadmin):
UPDATE files SET filepath = REPLACE(filepath,'files/','files/site-1/');
UPDATE node_revisions SET body = REPLACE(body,'src="/files/','src="/files/site-1/');
UPDATE node_revisions SET teaser = REPLACE(teaser,'src="/files/','src="/files/site-1/');
UPDATE boxes SET body = REPLACE(body,'src="/files/','src="/files/site-1/');

Installing Wordpress along side Cakephp

I have cakephp installed in the root directory. site.com/
i want to install wordpress blog at site.com/blog
but since cakephp will redirect all urls i am not sure how to do it ?
From: http://dogmatic69.com/blog/development/7-using-other-apps-with-cakephp-htaccess-config
One thing that is asked quite a lot on #cakephp is how to use other apps alongside CakePHP, and the answer giving is normally pretty ugly. Stick the files/folders in side webroot/. Although that does work, its not very nice. So ill show you a little trick with .htaccess files.
The first (really simple way) is to use a .htaccess inside the sub folder. For example you can have a copy of Joomla! running alongside cake with no issues when you have the .htaccess for Joomla! enabled. If the app does not have one and/or you would not know what to put in the .htaccess file you have another option
Make Apache stop processing rewrites if it finds a request for your sub directory. This is done by adding a rule for the sub directory and then telling Apache it is the last rule to process. The .htaccess file you want to edit is the one found inside your APP directory. All you want to add is the following line:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (some_folder/.*) $1 [L] # adjust the regex to what you want.
# normal cake rules
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
You can do this for as many sub folders as you wish, by changing the regex accordingly. Its pretty simple to do and a much cleaner way than having all your stuff inside the webroot/ folder of your APP.
Simply put the wordpress install into a "blog" folder in your /app/webroot folder.
Cake will load from the webroot as if the files were in a normal subfolder under a non-cake appliation. You may need to edit / adjust paths in the wp configs or .htaccess files throughout to get everything perfect but it isn't that difficult.
One way to do this is to have your domain pointing to site.com/cakefolder and then have another subdomain blog.site.com pointing to site.com/blog folder
This way to your user, it would always be site.com and blog.site.com

.htaccess - Rewrite a request to one directory before the request is handled by that directory?

I'm trying to exclude all BUT one directory from a rewrite rule. I want the request to be handled by the index.php file in the root directory which will then include the subdirectory's index.php file as part of a script after wrapping it with it's own code.
This is a really strange problem, since I'm trying to wrap Drupal within a Wordpress installation so that the existing site structure can stay put, and I can use a custom template to wrap the drupal output in a slightly customized wordpress theme.
If anybody has any idea how I can do this, I would be very very thankful.
htaccess files seem like arcane arts. Nobody seems to really get them that well, and I am no exception.
RewriteEngine on
RewriteCond $1 !^(drupal_directory|robots\.txt) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
The ! will exclude drupal_directory and robots.txt etc...

Resources