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!
Related
I'm currently hosting several applications on a quite out-dated wamp version but that's not really the case. Everything is working fine on that part, besides my laravel application.
My .htaccess in the www folder looks like this;
RewriteCond %{HTTP_HOST} ^sapdfr.org$ [NC]
RewriteRule ^((?!sapdfr/websitev3).*)$ /sapdfr/websitev3/public/$1 [NC,L]
The thing that's strange, is that the first page is working but when I'm going deeper into the website, it just totally breaks. I've been trying to rewrite these rules but I'm seriously mindblown about all the possibilities. Any help will be greatly appreciated since I'm entirely lost here.
Maybe a silly question but have you try that ? :)
Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this alternative:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
and then just redirect your domain to the laravel public folder
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?
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]
i'm creating a website, before uploading the site to web hosting i'm using XAMPP on windows. i was trying to use Search Engine Friendly URLs, for example:
http://localhost/mysite/[something]
to
http://localhost/mysite/index.php?p=[something]
i tried this .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9A-Za-z]+) index.php?id=$1 [QSA,L] #and also tried http://localhost/mysite/index.php?p=$1
before this i tried more examples but they didn't work. The real problem is that for example if y type
localhost/mysite/some_page
i get an error (403), using the [R] flag i realized that redirection is: http://localhost/C:/XAMPP/htdocs/mysite/index.php?p=some_page
i removed htaccess file and restarted apache but problam persist with some urls
Perhaps I'm trying to solve a different problem, but if the [something] always leads to content served by your index.php, then just send all requests to index.php and let that page use the URL string to get the variable you need to serve the right content (ie the string after the /).
You may need to turn off MultiViews in your .htaccess using Options -MultiViews.
The following is what you need in your .htaccess
RewriteBase /
# Where "/" is the location of your index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA, L]
Hope this helps.
Okay...My title is a bit of an exaggeration...
My site is built in PHP, and all the files I'm trying to "require_once" aren't being loaded. The only file I've changed is my .htaccess file. I don't know a thing about .htaccess and what I have is purely from searching the web. What is wrong? Thanks for any help in advance.
RewriteEngine on
<Files 403.shtml>
order allow,deny
allow from all
</Files>
ReWriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
ReWriteRule !index.php index.php [L]
Also, if I comment out the bottom two lines, my site works great.
Well, require_once has nothing to do with .htaccess file: it's a PHP directive, not an Apache one. You have to set correctly the include_path for your files and make sure these directories and files are reachable (i.e., with correct privileges set on them).
If you show the error message you got from failed require, it'd be much more simple to give you a specific advice on how to fix it.
UPDATE If what you need is redirecting all the non-AJAX requests for .php files into index.php, your .htaccess should like this:
RewriteEngine on
RewriteCond %{HTTP:x-requested-with} ^XMLHttpRequest$
RewriteRule . - [L]
RewriteCond %{REQUEST_FILENAME} !-d
ReWriteRule .php$ index.php
This basically means the following: "all AJAX requests - go for what you need, all non-AJAX requests IF you're not going for some directory and are ended with .php - go for index.php instead".
Without checking for .php (or some similar check) you will redirect to index.php all the script loading procedures; and, unless you do it from some external CDN, it's not what would work in your case. )
Try changing the last two lines to this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
If you want your URL's to look something like this (you probably do):
http://yoursite.com/some/path/somewhere
then change the last line to:
RewriteRule ^([^/]*)(.*)$ index.php?first=$1&second=$2
If that's what you want to achieve, ensure that if you're trying to go to:
http://yoursite.com/about
That there isn't actually a folder called about, this line:
RewriteCond %{REQUEST_FILENAME} !-d
Checks to see if a folder with the name "about" exists, if it does, then the page will not redirect, the same goes for files, say you go to:
http://yoursite.com/about.html
If about.html actually exists then the page will not redirect.
Hope that makes sense.
If you need more information, http://jrgns.net/content/redirect_request_to_index seems to be fairly succinct and helpful.