.htaccess on filesystem not working - windows

I tried using a .htaccess file on my computer (as in, not on an actual website), but it is not working. I looked for anything relevant, but all I could find were article discussing how Windows doesn't allow a file to be created with a dot as the beginning of the file name. I have made the .htaccess file, and am trying to remove the .html file endings from the URL:
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
However, when I typed the name of the file into the browser bar - without the .html extension - I received a 404 error. Why is the .htaccess not working on a file system, and how can I make it work?

You need to install a web server (e.g. Apache). The file system or web browser do not know how to interpret the .htaccess file, that is done by the web server.

Related

Laravel pretty URL

I'm going crazy here! I'm trying to learn Laravel and pretty URLs just don't work.
I have enabled mod_rewrite from my apache config file, I have set AllowOverride to All in my user config file and I have the following in my .htaccess file in public folder of Laravel installation:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
I enter http://localhost/~user/lara/public/index.php/users it works, but with http://localhost/~user/lara/public/users I get 404 Not Found error
The requested URL /Users/user/Sites/lara/public/index.php/users was not found on this server.
You can see that the redirection works fine, as public/users have turned into public/index.php/users but it says not found, even though when I manually enter public/index.php/users it show me the output.
I have read all the related questions on SO, none of the worked for me!
This is most likely caused by the fact that you are changing the document root during a request. From the looks of your URL (with the ~user segment) you are using mod_userdir or something similar, and what these types of plugins do it allow you to map a given URL prefix to a document root that is not the normal one for the server.
As such, you sometimes run into issues like this where the right .htaccess file is found, but its rewritten URL is against the original document root rather than the modified one and so your index.php file cannot be found (maybe, to be honest I don't really know, this is all conjecture). This is also why going directly to index.php/users works - the problem isn't the setup per se, but the mixing of rewrite rules and the change of the document root.
As such, the fix is to use a RewriteBase line, ad the following to the .htccess file:
RewriteBase /~user/lara/public/

.htaccess redirect to subdirectory for Ruby application deployed by passenger

My Ruby on Rails project is on justhost server. When I am creating there ruby project, it is creating this in folder rails_apps by default.
For my project, I have created symlinks.
ln -s ~/rails_apps/webworth/public ~/public_html/webworth
And
ln -s ~/rails_apps/webworth ~/public_html/webworth_app [Purpose of this symlink just for browsing files by ftp client]
I created .htaccess file in ~/rails_apps/webworth/public directory. Below is the .htaccess code
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv development
RailsBaseURI /webworth
SetEnv GEM_HOME /home5/worthgur/ruby/gems
and one .htaccess file in ~/public_html. Below is the code:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine on
Options +SymLinksIfOwnerMatch
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?webworth.com [NC]
RewriteCond %{REQUEST_URI} !webworth/ [NC]
RewriteRule ^(.*)$ "webworth\/$1" [L]
Everything is working proper with these structure of .htaccess files except one problem. Extra text is appending to all urls in my project i.e "webworth" for all links generated by routes.rb file. And I want to remove this extra text "webworth" from all URL's.
Now urls are generating for example in this manner.
http://webworth.com/webworth/tags/smartphones
while it should be http://webworth.com/tags/smartphones.
This extra text i.e "webworth" was added previously for the folder that has to be accessed since it was not in the document root for the site and because of this extra text, extra text is appending to all URL's generated by routes.rb file thru ~/rails_apps/webworth/public/.htaccess file [Reason: RailsBaseURI /webworth]
I guess this can be fixed by changing RailsBaseURI /webworth to RailsBaseURI / in ~/rails_apps/webworth/public/.htaccess file.
I did that and I am sure I could not write proper commands in ~/public_html/.htaccess file so that I can redirect the traffic from the public_html to the symlink (webworth) for my site. I used many options but couldn't figure out how it will work. Please help to write ~/public_html/.htaccess file properly to redirect the traffic from public_html folder to my symlink(webworth).
Justhost suggested this link: How to host the Primary Domain from a subfolder. But still I could not figure out the issue. Thanks
I had the same problem with justhost and I solved it without adding any redirect.
I set my rails app public folder to be the main site public folder.
I renamed the original "public_html" to "public_html_backup", just in case.
Added a symlink ln -s ~/myRailsApp/public ~/public_html
in my htaccess I changed RailsBaseURI /myRailsApp to RailsBaseURI /, resulting in:
<IfModule mod_passenger.c>
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv production
RackBaseURI /
SetEnv GEM_HOME /yourUserPath.../ruby/gems
</IfModule>
I hope this can help you.
Cheers

.htaccess will not redirect .php files

I have this in my htaccess, standard domain redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/fullnewdomain\.org\/$1" [QSA,R=301,L]
And it works fine for folders, subfolders, html files, images, etc. However, for some reason it refuses to redirect php files. Instead they still run as normal and do not redirect to the new domain. Any ideas as to why, and how I can fix it? It's almost like this host is trying to execute the php file before checking any rules ( And I'm not sure what I could do if that's the case! ).
Turns out there was an htaccess file the host had placed in the home directory ( One level above public_html ) to "counter" bots, but all it did was break anything else that tried to apply a rule to php files. Removed the file, problem solved itself.
For reference, hostgator was the host, and I still don't know why they felt the need to place the file there in the first place.

mod_rewrite to parent directory

I would like to create a .htaccess file that would do this logic:
If the requested file is not found try to find it in the directory
above.
I don't want to redirect the browser I would just like to internally rewrite the request.
I tried and searched for this a lot but always got stuck because (as I gather from the log) the where I could do the rewrite the path was always already without its per directory prefix. In the example below the .htaccess file is in the lang folder. If the lang specific file is not found it should just take the file from the parent folder. I understand that it is possible to do it by hardcoding the parent directory or by placing the .htaccess higher, but now that I suffered for so long in trying I would be very interested to learn if it was possible at all this way.
strip per-dir prefix: X:/localhost/htdocs/peopletest/public/img/root_cli/lang/en/loginhead.gif -> en/loginhead.gif
applying pattern 'somePattern' to uri 'en/loginhead.gif'
Thanks for the help.
SWK
Like this?
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-l
RewriteRule /[^/+]/([^/]+)$ $1

Ko3 - URL Rewriting problem - Removing index.php

I'm developing a website using Kohana 3 (1rst time I use a framework). Locally, everything works perfectly. At the moment, I have a default template controller, a multi-language support and my 'index.php' is correctly removed. So before going further, I tested if it worked on my server and I got an endless loop.
I followed the tutorial from the unofficial wiki for the multi-language implementation: http://www.kerkness.ca/wiki/doku.php?id=example_of_a_multi-language_website
A redirection to the default language occurs if the language is not specified in the uri so I figured the problem might have come from there even though it worked locally, so I removed it to see what happens without the redirection. Now, I can see my home page, but whatever the uri is in the web browser, the home page will always be called. I inserted the following line in my home view to check what the uri was:
request::instance()->uri() and effectively, the uri is always: /en/home/
I put the index.php back (in the bootstrap) and everything worked fine again, even with the redirection to the default language.
My first guess was that the uri isn't rewritten correctly, so I tried to change the .htaccess but no success...
Here's my .htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /dev/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
(btw I also tried the other RewriteRule in the unofficial wiki, doesn't work either)
Additional info:
Host: WebHostingPad
Apache: v2.2.11
PHP: 5.2.9
Rewrite_Module is activated
Thank you, I would really appreciate your help because I've been trying to fix this for days now and it's really starting to annoy me ;)
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
So the Kohana::init looks like this;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
If it worked with the original .htaccess, there's no need to change it at all.
The problem came from $_SERVER['PATH_INFO'] which returned no value...
This issue can be solved by adding the following line to the php.ini:
cgi.fix_pathinfo=0

Resources