I have apache & PHP on my local windows machine and my .htaccess rules work fine. I uploaded all my files to my Linux server and get different results. I have complete control of my Linux VPS. It isn't shared hosting or anything.
I created a file showme.php that all requests should go to. showme.php just outputs some $_SERVER variables just so I know it worked. But every request to the server gives me the 404 not found. The same request locally serves up showme.php like it should.
-Local example: http://localhost/somepage (I get the correct page rendered by showme.php)
-Server example: http://mydomain.com/somepage (I get a 404 message)
Here is my .htaccess file. I can't figure out why I get different results. Something with file permissions?
# AddType x-mapp-php5 .php
# AddHandler x-mapp-php5 .php
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . showme.php [L]
ErrorDocument 404 /page-unavailable/
<files ~ "\.tpl$">
order deny,allow
allow from none
deny from all
</files>
If you use phpinfo() and do a search for mod_rewrite (usually under configuration) you will be able to tell if you have the ability to use RewriteRules. This is usually why you see IfModule wrapped around your rewrites:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . showme.php [L]
</IfModule>
The answer was that in my httpd.conf I needed AllowOverride All set in one certain place. It was there in certain directories but I guess not as default..
Related
Bit of an odd one and I feel it must be answered but I can't seem to find it.
I have the following in my .htaccess file on a custom PHP site (NOT WORDPRESS):
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(contact|gallery|links)$ $1.php [L]
I cannot work out why "gallery" only is giving me a 403.
example.com/links
example.com/contact
Both work as expected and go to the desired pages. However
example.com/gallery
Redirects to
example.com/gallery/
And throws the 403 Forbidden error
gallery.php is a page and can be accessed from the same URL
There's nothing on gallery.php to redirect or check a query string or compare the URI. I cannot understand it.
Really flying blind on .htaccess stuff (always have), so any help greatly appreciated. What am I doing wrong?!
Also, tested it on https://htaccess.madewithlove.com/ and it said my work was correct, so really don't understand what it's finding incorrect. Why does it think gallery is a subfolder, not a URL?
And I have JUST realised, I do actually have a gallery folder, so if anyone can tell me how to use the htaccess to access the page and not the folder, I'd greatly appreciate it! If it helps, there's a .htaccess in the gallery folder to prevent direct access to images:
Options -Indexes
Options -ExecCGI
# AddHandler cgi-script .php .php3 .php4 .phtml .pl .py .jsp .asp .htm .shtml .sh .cgi
<Files ^(*.jpeg|*.jpg)>
order deny,allow
deny from all
</Files>
<FilesMatch "\.(jpe?g)$">
order allow,deny
allow from all
</FilesMatch>
Would they be conflicting?
Since gallery is a physical directory, you will need to set DirectorySlash Off in order to prevent mod_dir appending the trailing slash via a 301 external redirect. (This redirect gets cached persistently by the browser, so you will need to clear your browser cache before continuing.)
Note, however, that when disabling the DirectorySlash, you must also ensure that Options -Indexes is also set to prevent mod_autoindex from generating directory listings when the trailing slash is omitted from a directory, since a DirectoryIndex document in that directory will no longer prevent the directory listing being generated. See the security warning under the DirectorySlash directive in the Apache Docs.
You may also need to set RewriteOptions AllowNoSlash to allow mod_rewrite to match directories that have no trailing slash.
You then need to modify your existing rule...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(contact|gallery|links)$ $1.php [L]
Remove the first two RewriteCond directives. They aren't required since you are wanting to rewrite 3 specific URLs. If any of the conditions fail then the rewrite does not occur.
If contact, gallery or links happen to exist as physical files (very unlikely) or directories (gallery is a directory it seems) then the rewrite does not occur.
Summary
DirectorySlash Off
Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteOptions AllowNoSlash
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(contact|gallery|links)$ $1.php [L]
I just upload my contents to my new website (server) and noticed that Slir stopped working. I read a few forum boards and noticed it could be a path issue.
Does anyone know exactly what needs to be edited or changed for Slir to work?
My Home Directory is /home/username/public_html
I used that path in the slir.configuration, however it still didnt work. I received a Page Not Found.
I am also using codeigniter and php for reference.
Localhost slir worked fine without any configurations needed.
On some of the blogs I read that slir may be having trouble with the .htaccess, but I'm not that familiar with that to change it.
# Prevent other scripts from interfering with SLIR
php_value auto_prepend_file none
php_value auto_append_file none
# Pretty URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
RewriteRule . index.php [L]
</IfModule>
# Prevent viewing of the error log file in its default location
<Files slir-error-log>
Order Deny,Allow
Deny from All
</Files>
MORE INFO
I just spoke to the web hosting IT department and they mentioned that only one .htaccess is accessible at a time. He had to close down the root .htaccess to use the slir .htaccess.
How can I fix this issue on my VPS server?
Issue Fixed!
FIXED
Just comment out the top 2 items and it worked! on the slir .htaccess
# Prevent other scripts from interfering with SLIR
#php_value auto_prepend_file none
#php_value auto_append_file none
# Pretty URLs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
RewriteRule . index.php [L]
</IfModule>
# Prevent viewing of the error log file in its default location
<Files slir-error-log>
Order Deny,Allow
Deny from All
</Files>
I had this working on an old server and unfortunately had to switch over to a new one which had to be remade from the ground up, and now this .htaccess is not working, it throws Error 500 to any request in its directory.
Options -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+admin\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ admin.php?page=$1 [L,QSA]
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
<Files global.php>
Order Allow,Deny
Deny from all
</Files>
Options All -Indexes
The goal is to send requests to www.domain.tld/directory/log to www.domain.tld/directory/admin.php?page=log
and to also prevent viewing of the .htaccess file itself or the file global.php
As a side note I did try writing it directly into apache2.conf as a directory setting however this caused the apache2 service to be unable to start.
To know what is the problem exactly, you have to check apache error_log file
for cPanel Servers, you can try this command:
tail /usr/local/apache/logs/error_log
now the most popular 500 error for .htaccess is the use of Options line
many servers configs don't allow execution of Options in .htaccess for security reasons (overwrite configs, enable Perl execution... etc)
most server too have Options -MultiViews and Options All -Indexes already,
comment Options lines with # and your website should works just fine.
Hello I am using the following htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
For doing the laravel routing.
When I surf to example localdevurl/public/users I get the following error ( 404 )
Not Found
The requested URL /Users/username/Sites/sitefolder/public/index.php/user was not found on this server.
But as u see it shows the index.php in the error. When I put index.php in my url it does work indeed. I have turned on everything in my apache config.
httpd.conf
Can anyone see what I am doing wrong here?
In your .htaccess file, you are passing the request after the index.php part, instead of allowing laravel routing system to process it, this is:
RewriteRule ^(.*)$ index.php/$1 [L]
should be as the original .htaccess
RewriteRule ^ index.php [L]
I had the same problem with the index.php part, this is how I solved: There is a problem when you have userdir module enabled, which it seems to be the case based on the URL of the error message.
Possible solutions:
Create a symlink in the webserver folder to the public laravel project folder of the user web directory. e.g.: # ln -s ~/public_html/mylaravel4/site/public/ /var/www/mycoolsite
Then you can access http://localhost/mycoolsite
Replace RewriteCond and RewriteRule lines with this: FallbackResource /index.php
Make sure you have AllowOverride set to All instead of None for you particular vhost, and also set Order allow, deny rather than Order deny, allow in httpd.conf.
AllowOverride all
Order allow, deny
I am trying to setup and learn the Fat Free Framework for PHP.
http://fatfree.sourceforge.net/
It's is fairly simple to setup and I am running it on my machine using MAMP.
I was able to get the 'hello world' example running just fin:
require_once 'path/to/F3.php';
F3::route('GET /','home');
function home() {
echo 'Hello, world!';
}
F3::run();
But when I try to add in the second part, which has two routes:
require_once 'F3/F3.php';
F3::route('GET /','home');
function home() {
echo 'Hello, world!';
}
F3::route('GET /about','about');
function about()
{
echo 'About Us.';
}
F3::run();
I get a 404 error if I try the second URL: /about
Not sure why one of the mod_rewrite commands would be working and not the other.
Below is my .htaccess file:
# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
# Disable ETags
Header Unset ETag
FileETag none
# Default expires header if none specified (stay in browser cache for 7 days)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A604800
</IfModule>
So my friend actually helped me out with this issue. I ran into the exact same problem, but basically I'm using MAMP also and have all my Fat Free files within a fatfree dir within htdocs of MAMP.
The solution is you need to mod the RewriteBase to point to /[dirname]/ instead of just / and then change RewriteRule to /[dirname]/index.php.
My .htaccess looks like this:
RewriteEngine On
RewriteBase /fatfree/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /fatfree/index.php [L,QSA]
After that's set, you can follow the example in the Fat Free doc exactly and it'll work like a charm. This stumped me for a while and this was all it needed. Also, if you're using MAMP, edit the httpd.conf file in /Applications/MAMP/conf/apache and be sure to alter the following:
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
to
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
Basically change None to All.
If you're running F3 under a subfolder, you must change the RewriteBase in .htaccess to match the folder.
In your .htaccess you have 'index.php' it needs a slash ... '/index.php'
# Enable rewrite engine and route requests to framework
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L,QSA]
otherwise when it tries to rewrite /about/ it will look for /about/index.php instead of just the root /index.php
I just had another thought.. it 'is' possible that althought mod_rewrite is intalled there may be a quirk with the server causing it not to rewrite..
If the global route below doesnt work you might want to test the rewrite
RewriteRule ^/google http://www.google.com [L,NC];
You could also try a global route for the directory
F3::route('GET /about/*','about');
but that means anythin under domain.com/about/ ...... anything ... will reroute to the about function...
A note about mod_rewrite and FF
As you said, FF is givikng you a 404 because it is expecting '/' instead of '/index.php'... However, it is the index.php which is expecting the difference..
To demonstrate that, i believe you can duplicate your
F3::route('GET /','home');
as
F3::route('GET /index.php','home');
and the page should display...
The reason for this is if you just go to the / directory (or /index.php) eitehr way apache servesx the index.php page....
The mod_rewrite allows you to redirect the /about and have it redirect to the index.php.. So if your rewrite rule is not working then the redirect/rewrite does not happen and you will get a 404...
As i mentioned above, test the mod_rewrite with the google rule.. then try to go to http://localhost:80/google
if it does not redirect you to google then your rewrite engine is not working... (probably an issue with the windows configuration..)
to enable mod_rewrite under windows:
Open your http.conf
Find this line:
#LoadModule rewrite_module modules/mod_rewrite.so
remove the comment mark (#) from the line... so you have:
LoadModule rewrite_module modules/mod_rewrite.so
Save the file and restart apache..
Alternatly.. I think you can just say:
LoadModule rewrite_module modules/mod_rewrite.so
at the start of your htaccess file...
I banged my head on this for 2 days. I debugged htaccess and php both. The actual problem is this :
If you copied the .htaccess file from their fatfree-1.4.4 zip download, its not .htaccess its htaccess (. is missing) Just rename this file to .htaccess from htaccess and everything will work perfectly as its mentioned in the document !!!
I am using this .htaccess works for non-root folders too
Options -Indexes
IndexIgnore *
RewriteEngine On
RewriteCond $1 !^(index\.php|images|main\.css|form\.css|favicon\.ico|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: If you want to call your .htaccess file something else, you can change the name of the file using the AccessFileName directive. For example, if you would rather call the file .config then you can put the following in your server configuration file:
AccessFileName .config
here
This response may be too late for you but I had the same problem yesterday.
It sounds like the problem is apache is not rewriting urls. I had the same issue when trying to get F3 running on OSX 10.7 - the 'GET /' route would work but not the 'GET /foo' as the F3 index.php was in a subdir for localhost/F3. My solution was to:
ensure the .htaccess was set as you have.
ensure mod_rewrite.so was enabled in apache's httpd.conf
ensure that you set AllowOverride All (mine was None) for your web directory in httpd.conf (further down the file).
restart apache
Without step 3, apache will ignore any rewrite directives. I discovered this by changing the permalinks on a local wordpress install and they failed indicating the problem was the apache config, not F3.
I'm running this with a MAMP stack.
I renamed their folder from "fatfree-master" to "f3".
I put that folder next to htdocs.
Their .htaccess file (now inside MAMP/f3/lib) remains untouched.
My .htaccess (in my web subfolder) is stock standard as per their example:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]
Hope this helps someone.
I had the same issue and i solved it by moving the .htaccess file to the root directory of the fatfree project.
create a file .htaccess with folowing code at root directory
# Enable rewrite engine and route requests to framework
RewriteEngine On
# Some servers require you to specify the `RewriteBase` directive
# In such cases, it should be the path (relative to the document root)
# containing this .htaccess file
#
# RewriteBase /
RewriteCond %{REQUEST_URI} \.ini$
RewriteRule \.ini$ - [R=404]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]