htaccess - Access root subfolder - php

I believe this question is purely PHP related, a language in which my knowledge is limited and I'm still learning things, keep that in mind.
I installed Ionize CMS on a client's server and everything is going smooth. But there is one little thing I wish I could do and it reaches the extent of my PHP knowledge.
I want to know if it is possible to access the content of a folder located at the root of my site from my web browser, which is not ionize related. I need to access the old backup of a website. In other words, I want to be able to write in the url the path and see the content in the web browser. Ex:
http://mysite/backup/index.php
For the moment, if I try that, the page displays the ionize 404 not found message.
I guess it has something to do with the htaccess file, but I'm really not sure how to modify this file to do what I want, if possible.
I did a bit of research and found this code, but if someone could explain it to me that would be great, as my php knowledge is not that great like mentioned earlier. I don't want to test it right now without knowing what it does, I don't want to permanently damage my website rewrite function..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
Anyone could spare some knowledge on the feasibility of my question?
Much appreciated

This rule basically says if the requested URI (folder) is subdirectoryname1 or subdirectoryname2don't do anything and stop processing the rules. So a rule like this should work for you. The rules have to come before your ionize rules.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
You can also just do this for your situation which does the same thing.
RewriteEngine On
RewriteBase /
RewriteRule ^backup/?(.*?)/?$ - [L]

Related

Rewrite/hiding some URL in .htaccess

I'm trying to get right syntax for .htaccess without any result...
I've a URL structured as domain.com/app/public/pageName .
It's working fine but I would "hide" the 'app/public/' part in browsers, basically doing something like:
[real URL] domain.com/app/public/pageName -> domain.com/pageName [what users type and see in browsers]
I think in that way it should be more readable and seo-friendly.
As I understood from docs (and maybe it's wrong because it's not working...) I should tell to Apache to map/redirect all URL like domain.com/pageName to domain.com/app/public/pageName , but only internally, in order to show the minimal URL in users' browsers.
Right now I have something like:
RewriteEngine on
#RewriteBase /app/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ https://localhost/app/public/index.php?url=$1 [QSA,L]
(I'm using full URL with https://... in order to get something that will be quick and easy to adapt when I upload all to my hosting, is it right?).
Problem is that RewriteRule actually change the URL, because it perform a redirect and URL rewrite it's not handle internally.
So, first of all: is it possible what I'm trying to do? If so, how can I handle the URL rewrite only internally?
Everything should be uploaded to a shared hosting, so I don't have other than .htaccess.
Anyway, I can consider to upgrade to a vps if there are not other possibilities...
Thanks!
==============
EDIT (should be more clear now)
tl;dr version:
I'm looking for a method that let users to type domain.com/pageName (and they will see that address in their browsers) and rewrite internally that URL in order to point to domain.com/app/public/pageName.
==============
More: after /app/public/ there can be an arbitrary number of elements, separated by / . All of these elements are appended at the end of the URL after index.php. At the end URL looks like:
domain/app/public/index.php?url=lot/of/elements/here
This is already working with the RewriteRule posted above, I would keep that too.
Thanks!
This is working fine for me, Hope it will work for you as well.
Check .htaccess here
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/app/public
RewriteRule ^app/public/(.*)$ /$1 [L,QSA]
Just for reference, I found a solution, maybe will be usefull for someone.
Basically I moved .htaccess to the root server (instead of /app/public directory) and changed the RewriteRule as follow:
RewriteEngine on
RewriteBase /app/public/
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [PT]
Now it's working (at least on localhost).
What do you think? Are there any side effects with this config?

Redirecting all requests to index.php with exceptions

I've searched everywhere trying to find a solution to something I thought was a particularly common problem, but I can't seem to find anything that works.
I'm using mod_rewrite to redirect all requests via my own CMS (index.php). Here's the htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
(The above mod_rewrite is exactly the same as the code found in a standard Wordpress installation which is why I'm perplexed as to how I cannot find a solution for the following problem)
I want to add some image processing to my video thumbnails. I have written a php script (video-image.php) that works great but I cannot seem to find a means to redirect the images urls whilst keeping the index.php redirect intact. The code I'm looking for does something like this:
RewriteRule ^images/video/(.*)/(.*).jpg /images/video/video-image.php?video_image_id=$2&video_image_width=$1 [NC]
But the above code seems to clash with the mod_rewrite that sends my requests to index.php. It seems I can either redirect the images to video-image.php or redirect my pages to index.php but there must be a way to do both?
I've always found mod_rewrite confusing so apologies if I'm not explaining myself clearly enough. All php scripts function perfectly well without the mod_rewrite so I'm certain it's not a php issue.
If anyone can shed any light on this problem or point me to an answer I'd really appreciate it!
The gist of your issue was the ordering of rewrite blocks. You usually put the more specific ones above the general rules. In your case:
# specific
RewriteRule ^images/video/(.*)/(.*).jpg /images/…
# generic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
A better approach for Apache 2.4 and later is to use FallbackResource instead of the RewriteCond/Rule blob:
RewriteRule ^images/video/(.*)/(.*).jpg /image
FallbackResource index.php
Two more things:
<IfModule mod_rewrite.c>
</IfModule>
Is something that you should not commonly use. Conditional directives make sense in Apaches core configuration. For .htaccess RewriteRule blocks it's less advisable. It's unlikely that mod_rewrite randomly disengages at runtime. And if ever, you'd rather want HTTP 500 errors in your log instead of users seeing 404 Not Found results.
Also RewriteBase can shorten some rules, or abstract their residence. But you also shouldn't use it habitually. Instead just prefix blog/ to your match rules, and assemble all rewrites in the DOCUMENT_ROOT/.htaccess (or better yet VirtualHost section for performance).

Rewrite Mode and PHP using .htaccess not working (Error 404)

Here is my .htaccess:
RewriteEngine on
RewriteRule !\.(js|ico|gif|ini|jpg|png|css|html|swf|flv|xml)$ index.php
I've been using this file for about a year now and frankly, if you ask me I'd say it means: If you're trying to access something NOT ended with js, ico, gif... flv, xml THEN redirect to index.php
Now I'm trying to deploy an application at a new server (centOS WITH mod_rewrite enabled) and I get the Error 404 when trying to access stuffs that usually works (at a different web server, for instance).
Since I know too little about it, I'd like some input on what should I be looking for to find the problem. Thanks in advance.
You should perform that kind of match in RewriteCond
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !\.(js|ico|gif|ini|jpg|png|css|html|swf|flv|xml)$
RewriteRule .* index.php
Note: the first rule is needed so that the rules won't loop (exclude index.php itself from rewriting).

use .htaccess to deal with requests for backend and frontend

First of all, I apologize for any mistake in English
well, my question is this:
I have a folder that has the backend, and receives requests in the following path
[root]/backend/www(which contains an index.php file that handles requests)
I have a folder that has the frontend, and receives requests in the following path
[root]/frontend/www(which contains an index.php file that handles requests)
I have also a folder named common that is shared between the backend and frontend (contains the libraries of the framework, among other files)
what in need, is when the access to this location:
h**p://localhost/andre/admin
rewrite it to:
h**p://localhost/andre/backend/www (how it currently is)
In other words, instead of accessing the backend by:
h**p://localhost/andre/backend/www
use this address:
h**p://localhost/andre/admin
all other requests that do not point to:
h**p://localhost/andre/admin
be accessed by:
h**p://localhost/andre/ (ie, point to
h**p://localhost/andre/frontend/www)
(I hope you can understand what I want)
I need help, on a way to do this with .htaccess file, I can not use Symlinks or Subdomains for this problem...
I've searched a lot in Google and here, but found nothing that worked or who could help me.
PS: I am using Yii Framework with YiiBoilerplate, but I think the solution should not be out there
Thanks in advance!
Solved, with this code:
RewriteEngine On
RewriteBase /andre/
RewriteRule ^admin(/.*)?$ backend/www/index.php/$1 [L,NC]
RewriteCond %{REQUEST_URI} !/(frontend|backend)/ [NC]
RewriteRule ^(.*)?$ frontend/www/index.php/$1 [L,NC]
Put this code in your /andre/.htaccess file:
RewriteEngine On
RewriteBase /andre/
RewriteRule ^admin(/.*)?$ backend/www$1 [NC,L]
RewriteCond %{REQUEST_URI} !/(frontend|backend)/ [NC]
RewriteRule ^(.*)$ frontend/www/index.php/$1 [L]

.htaccess file not working with certain servers

Hello and thank you for taking the time to help me solve my problem. I like to build all of my web projects using a simple MVC Framework I have created along my travels. I seem to be having a problem getting the .htaccess file to work correctly on specific servers.
For example...
If you go to:
http://thomsonbrothersindustries.com/northside/ and attempt to access a page (right now only "About Us" is functional - http://thomsonbrothersindustries.com/northside/about) but as you can see the "about" page just directs you to a 404 Error.
Now, if you go to: (the same site, but on a different server)
http://ericzdisposal.com/northside/
http://ericzdisposal.com/northside/about
everything works fine...
Here is the .HTACCESS file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
My privileges are limited on the server that is currently not working and I'm still working on getting better access to domain tools, but in the meantime I'm just trying to get a better idea of the problem and hoping there might be an easy fix in my future.
In addition to what #bigman suggested, make sure that AllowOverride directive setting is not very restrictive for your website directory. For mod_rewrite to work in .htaccess, you need to set AllowOverride FileInfo, but for testing purposes, you can set AllowOverride All.
Looks like adding the directory into the .htaccess file did the trick!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ **/northside/**index.php?rt=$1 [L,QSA]
I didn't realize this was important because on the other server it did not matter
Thanks all!

Categories