.htaccess works locally, but gives 404 on GoDaddy - .htaccess

I have this code in my .htaccess file:
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteRule ^(design|JS|css|images|remoteLibraries|remoteLibraries/xAJAX/xajax_js/)($|/) - [L]
RewriteRule ^([a-zA-Z_]+)$ index.php?action=$1
RewriteRule ^([a-zA-Z_]+)/([a-z_A-Z]+)$ index.php?action=$1&tip=$2
It works fine on my local Apache server, but when uploading it to GoDaddy all I get is 404 Not found error ...
Any idea?

1) I recommend that you set a RewriteBase, usually just
RewriteBase /
which helps standardize where the rewrite takes effect, since the directory structure may be different between the local and remote servers.
2) I also recommend that whenever unexpected rewrite behavior crops up it is important to set
ErrorDocument 404 default
so that the Go Daddy 404 page is not redirected as well.

Related

Using .htaccess is giving 500 error but working for file

I am not an expert using .htaccess but here is my scenario:
My .htaccess is in the root.
The only content is below.
To access the pdf file is working fine but not when I am trying to access the file with parameters that is going to return data or send data.
I know I am missing something but what?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^admin$ login.php
RewriteRule ^admin-system/balance/get$ source/Support/Action.php?action=balance-get
RewriteRule ^admin-system/balance/list$ source/Support/Action.php?action=balance-list
RewriteRule ^admin-system/balance/set$ source/Support/Action.php?action=balance-set
# This one is working fine.
RewriteRule ^admin-system/terms$ app/helper/files/term.pdf
Options +Indexes
</IfModule>
HTTP 500 - when talking about htaccess - is a syntax error. IMHO, just remove the following line:
Options +Indexes
It's highly possible, that Options is not allowed there - the apache error log will give you a clue about it.

.htaccess rewrite rule for same words

I have two rules causing problems:
RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php
I know that I could use "post/create" but these are just two rules out of more that are having all the same problem.
I worked with this rules perfectly on localhost (XAMPP).
However, once I moved the files to my hoster and visited "sub.domain.com/posts/create" it redirects me to posts.php instead of postscreate.php.
Why does it work fine on localhost but not on my hoster? And how can I fix it?
My full .htaccess looks like this (with the two rules only):
AddType application/x-httpd-php .html
RewriteBase /
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://sub.domain.com/$1 [R=301,L]
Options -Indexes
RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php
The .htaccess on localhost is exactly the same except the https rules. I also tried the .htaccess without the https rules on my hoster but it still didn't work.
Why does it work fine on localhost but not on my hoster? And how can I fix it?
It is most likely due to option MultiViews being turned on on hoster but turned off on localhost.
To disable this use this line on top of .htaccess:
Options -MultiViews
Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.

.htaccess second RewriteRule note working

I have a PHP page like example.com/new/info.php?title=example. The .htaccess is in folder /new/. I tried it in the main directory also. My .htaccess looks like this:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?title=$1 [QSA,L,NC]
RewriteRule ^info/([a-zA-Z0-9_-]+)/$ info.php?title=$1 [QSA,L,NC]
The first Rule is working, but the second sends no GET['title'] to the server. The site info.php loads but without the variable. I have tested it on my localhost and it's working. I load it on my webspace and the second rule is not working.
I tried it also without new directory example.com/info.php?title=example and same not work.
What is my mistake?
It sounds like you have MultiViews enabled (possibly in the server config). You need to disable MultiViews for this to work. Add the following at the top of your .htaccess file:
Options -MultiViews
With MultiViews enabled, mod_negotiation will issue an internal subrequest for info.php when making a request for /info/example/ - before your mod_rewrite rule is processed, so no parameters are passed.

.htaccess URL Rewrite Failing - The requested URL was not found on this server

I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is http://localhost/site and www.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
Remove the 'RewriteBase /site' and try removing the / before index.php
The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]

403 error when access controller in subfolder (CodeIgniter)

This is my application skeleton:
application
controllers
backend
[backend_controllers_here]
[frontend_controllers_here]
models
[shared_models_for_both_backend_and_frontend]
views
backend
[backend_views_here]
[frontend_views_here]
...
system
index.php
.htaccess
This is my .htaccess file content:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
# DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
It's nothing wrong when I type on address-bar something like these (for frontend):
mysite.local
mysite.local/index.php
mysite.local/index.php/frontend_controller
mysite.local/frontend_controller
But for backend I had a 403 error when try to access:
mysite.local/backend
mysite.local/backend/some_backend_controller
However, with index.php in URL everything is fine.
mysite.local/index.php/backend
mysite.local/index.php/backend/some_backend_controller
Am I missing something here?
Thanks for your time!
check the permission for the backend folder. it maybe prevents the webserver from reading the actual content of the directory.
The permission should allow reading for everyone
What does your config/routes.php look like? Might try something like this:
$route['backend'] = "backend/controller/method";

Resources