.htaccess mod_rewrite trouble - .htaccess

So here's the thing .. I've been working on my webpage for some time now. I have a .htaccess in the root folder that contains only a few rows of rewriting rules and nothing else. It works fine on localhost but when I upload it to my host it just throws 404 error (my host is 000webhost.com). I tried eliminating every rule one by one to see where the error is, but nothing happened, I even deleted the contents of the .htaccess file and still it gives a 404 error. The only solution that worked (so far) was deleting the .htaccess file and only then the homepage appears. Any suggestions?

I just found out that my host doesn't support UTF8 encoding (i guess?) in .htaccess file so i changed the encoding to ANSI and it did the trick.

Have you tried the suggestion on your web host's site:
http://www.000webhost.com/faq.php?ID=16
they are suggesting you put this at the top of your .htaccess
RewriteBase /

Related

Can't access files on Magento root

I am looking to install an SSL on my domain name and in order to do so I need to upload a .htm file to the root and access it via the browser, but when I do so, I keep getting a 404 error - this is with any .html page on the root - nothin shows up.
I have edited my htaccess file as well as deleting it all together and still no luck.
The file i'm trying to reach is: http://www.elmershardware.co.uk/xtt5ughh.htm
If someone could help point me in the right direction of fixing this I'd be really appreciative
Thanks
G
I think there is nothing to do with .htaccess. It's something related with your apache conf.
In your apache configuration file check if in DirectoryIndex appears
index.htm as a entry, add it if it doesn't appears and restart apache. Then , try again

htaccess RewriteEngine working for HTTP but not HTTPS

I am trying to redirect URLs such as www.mysite.com/foo/bar to www.mysite.com/foo/index.php?foo=bar.
To do this I am using a couple of lines in the .htaccess file, they are as follows:
RewriteEngine On
RewriteRule ^foo/([a-z]+)/?$ foo/index.php?bar=$1 [NC,L]
This works great for connections made over HTTP but I really need this to work over HTTPS as well. When I go to https://www.mysite.com/foo/bar I just get presented with the 404 Not Found error page.
Any help to get this working over HTTPS (or an explanation as to why it cannot be done over HTTPS) would be great. Thanks.
EDIT:
After reading a few comments here is a bit of an update.
I do have an SSL certificate for the site and HTTPS is working fine elsewhere on the site
The document root is the same for both the HTTPS and the HTTP versions of the site. I checked this out using echo $_SERVER['DOCUMENT_ROOT']; - both return the same thing.
I did notice that (when I removed my customised 404 page) that the error shown is: The requested URL document_root/public_html/foo/index.php was not found on this server. I do not have any idea why this might be the case when, if I access the file directly, I can use it fine.
Hopefully this extra info might help a bit.
After some more searching for solutions and looking at examples of .htaccess files I found the solution. I needed to add the following line to my .htaccess file:
RewriteBase /
I am still unsure as to why, without this line, it worked using HTTP but not HTTPS but everything is working well with the addition of this line.
I am no expert in this area but I found a nice explanation of what RewriteBase does here (Line 4): http://randomtype.ca/blog/the-wordpress-htaccess-file-explained/

my .htaccess is giving me a Forbidden error

I have the following in the root directory of my site:
RewriteEngine on
RewriteRule ^([^./]{3}[^.]*)$ /index.php?page=$1 [QSA,L]
The .htaccess should be redirecting any request 3 chars or longer without . in the string to the index.php/$string-text as to query my CMS db for output, however when i try and load the index page I get a 403 forbidden error... My .htaccess knowledge is quite basic so try and be easy with me! :)
Thanks
Ric
There does not appear to be anything unexpected with your .htaccess file. If the mod rewrite was not configured correctly, I would expect to see 404 errors or the user being redirected incorrectly. As this does not appear to be the case; you need to widen your search to check that there are no security settings out of place.
I cannot see anything obvious in the httpd.conf file, but here are some of the steps you might want to take.
Remove the .htaccess file - if the website loads okay - then this file is causing an issue somehow; if it doesn't then there is something else wrong.
Check permissions on the web directory being used; there may be a permissions problem.
Check the httpd error log for suggestions.
Ask the question over at serverfault.com or poweruser stack exchange sites.
Ok! So I found the issue, The apache error_log file explained I needed to add this into my .htaccess file and the httpd.conf file -> "Options +FollowSymLinks +SymLinksIfOwnerMatch" and it worked! Now to create my VHost and I am good to go!!! Thanks!!!!!
Thanks
Ric

htaccess rewrite resulting in 500 Internal Server Error

I am trying to get pretty urls using htaccess for SLIR image resizing plugin.
I want to rewrite something like below:
Before Rewrite:
localhost/img/600x400/slider/image.jpg
After Rewrite
localhost/application/public/slir/index.php?r=slir&w=600&h=400&i=img/slider/image.jpg
But the following code is returning a 500 Internal server error...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/([0-9]{1,4})x([0-9]{1,4})/(.*)\.(gif|jpg|jpeg|png) application/public/slir/index.php?r=slir&w=$2&h=$3&i=$1/$4.$5 [NC,NE,QSA,L]
</IfModule>
Please help me.....
UPDATE
I thought it was a File Permissions issue...
so I checked all the related directories and files, surprisingly there were all 755/644.
Then I directly checked the /application/public/slir/index.php. It was not accessible.
I created another file named hello.php in the same slir directory and hello.php was accessible.
Then I moved the SLIR directory to the another folder named public. Here, both the index.php and hello.php were accessible.
After that, I moved SLIR directory to back to the original scripts folder. In scripts folder, hello.php is accessible but index.php is not accessible.
Now, Both files have same permissions and are in same folder.. I dont know what is happening here... :/ :/
Someone please help me......
In case anyone else is looking at this - the problem I found was these two lines in the htaccess file:
php_value auto_prepend_file none
&
php_value auto_append_file none
some servers don't allow them.
moving them to my php.ini file solved it for me:
auto-prepend-file = none
auto-append-file = none
That is probably because you are editing the .htaccess file with a Windows based editor like notepad. Notepad adds some characters to the file which you can't see, but they mess with the .htaccess. I recommend using an editor like Notepad++ and setting the mode to Unix, so it won't mess with the server..
Speaking technically that is because Linux and Windows have different type of EOL ( End Of Line ) so that notepad adds some characters to the end of every line to go to the next line, but Unix won't recognize them, because it has it's own type of EOL..
Slashes are normally forbidden in query strings, but you can enable them by setting
AllowEncodedSlashes directive.
You may also want your rewrite rule to use percent encoding for slashes (that is %2F) so after rewrite:
localhost/application/public/slir/index.php?r=slir&w=600&h=400&i=img%2Fslider%2Fimage.jpg
See also How do you configure apache php to accept slashes in query strings
Duplicate, phrased very differently:
Has anyone used Smart Image Resizer on subdomain sites?
The problem is the subdomain...

ModRewrite only works for some options

My htaccess file is the following:
RewriteEngine On
RewriteRule ^blog/post/([0-9]+) /blog.php?post=$1
RewriteRule ^blog/page/([0-9]+) /blog.php?page=$1
RewriteRule ^work/([0-9]+) /work.php?ID=$1
The work.php rule is working, but the two blog rules aren't. They used to all work, but I recently moved my server. Any ideas why this would be?
Thanks in advance!
Edit:
Woah, I noticed that I had a work folder, but no blog folder, so I made one, and now this works. Any ideas why?
I just set up a (virtual) server on my local Apache 2.2 installation, running PHP 5.2 as a module. The server's document root contained only php files to (simplistically) process the examples you gave above (just echoing the parameters from $_GET). My .htaccess file at the document root contained only what you specified above, and nothing else. The document root did not contain the subdirectories /work or /blog (or /blog/post or /blog/page).
My setup did not have any problems at all rewriting the SEO-friendly URLs to the proper PHP files, which in turn echoed the parameter values I expected from $_GET.
There is something other than mod_rewrite requiring the existence of the subdirectories, and Apache is hitting (and thus requiring) it before it processes the rewrite rules. Not sure what it is, but it does not appear to be mod_rewrite, given the rules you have above.

Resources