.htaccess file is not working with hostgator - php

I have migrated my CRM application (developed PHP) from hostgator VPS to hostinger,
My application Folder structure is crm\leadstracer1.1{other php files}. I had kept a .htaccess file in crm folder, to avoid '.php' extension on URL, that was working fine on hostgator. But after migrating hostinger its not getting work, I am using CentOs server, I tried instructions from following links
Linux CentOS 7 - Configuration of httpd.conf file through .htaccess
Codeigniter URL rewriting .htaccess is not working on CentOS
But nothing get work out.
Please see the content of my .htacess file.
RewriteEngine On
RewriteRule ^$ leadstracer1.1/views/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ leadstracer1.1/views/$1.php
It would be great if someoone help me regrding this
Thanks

Have you correctly configured your httpd.conf or virtualhost conf file to allow the use of htacces file?
Usually you have to change it to make it works.
There should be a directive called AllowOverride none that must be configured as All for example

Related

Apache rewrite not working on custom extension

I'm working on a PHP web app which will route every incoming request to the index.php same as WordPress or Joomla.
Following .htaccess is used to implement the feature.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It is working on Wamp server [Windows] and IIS but when I migrate the app to the Ubuntu 16.04.02 [Apache 2.4.18, php7.0.18, Google Cloud Engine], it stops working for some custom extension file. It still working on normal php files thought.
I created a folder called service to put the web service php files and named the files as ****.svc.php and used with ****.svc url. It was working fine before but it is not on the Ubuntu and shown the following error.
Not Found
The requested URL /service/retrieve_opened_rs.svc was not found on this server.
Apache/2.4.18 (Ubuntu) Server at ******* Port 80
I believe this is the configuration issue but I still cannot figure out how to fix after 3 days. Please help me. Thanks in advance.
You probably have the Multiviews option enabled. This never behaves well along with rewrite rules, especially with "double" extensions like .svc.php
Add this at the top of your .htaccess file and that should take care of it:
Options -Multiviews
You might have to tweak your AllowOverride directive (from the main Apache conf) if you don't have the rights to modify Options from an .htaccess file.

Codeigniter - getting 404 Not Found error

We have two hosting packages at godaddy. Our live website is working fine using following .htaccess file. Website is accessible without using index.php in url.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
We used same htaccess file and same code on other hosting that is also by godaddy. We just wanted to make production and development instances seperate. But on other hosting with same code and htaccess file, website shows 404 page not found error but website works fine with index.php in url.
We have same php version on both server. Just wants to know what could be the issue?
I also faced the similar problem when I move my 100% working code to dedicated Debian server. After 3 hours of research, i found out why htaccess file is not working.You need to allow overriding of htaccess in Apache Configuration.
Here are the steps.
Step 1:
Add this in htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Step 2:
Remove index.php in codeigniter config
$config['index_page'] = '';
Step 3:
Allow overriding htaccess in Apache Configuration (Command)
sudo nano /etc/apache2/apache2.conf
and edit the file & change to
AllowOverride All
for www folder
Step 4:
Restart Apache (Command)
sudo /etc/init.d/apache2 restart
Before you make any changes in apache2.conf file make sure to make a backup copy of that file. If you are using Debian server you can avoid sudo command. I believe you know how to connect to your server using ssh client software like putty. Comment below if this method does not work for you.
Follow this
Create a new .htaccess file in your public_html/Project root
Paste the following code
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]
Optional
If you can ssh into the server using command ssh username#ip_address on a command line either Linux terminal or Putty
The username is the one given to you by GoDaddy or you can use root
The ip_address would be the Public IP to your host you can find it in your hosting panel
Run the command sudo a2dissite 000-default
The command disables the default apache config that handles request
Goodluck!
You can use this. This works for me in godaddy hosting.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
try this one.. it's works for me..
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
I have faced the similar problem when I move on godaddy server.And It's work for me.
Add this code into your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
In config file:
$config['base_url'] = 'domain.com';
$config['index.php'] = '';
And Set AllowOverride to All in your httpd.conf
set the correct permission on the /cache folder, rather than just making the folder writable you need to make it reclusively writable.
I hope it will work for you.
Try to lowercase all your controllers. This fix the problem for me.
in index.php you echo "test" and run .then you can check whether it is called or not.
in config file enable error log .
Make your /application/logs folder writable.
In /application/config/config.php set. $config['log_threshold'] = 4;
check the log /application/logs folder
I have limited knowledge in server networking but this should give you a few ideas.
First ,you must know what is .htacess file is. you can check it here link
.htaccess is a configuration file for use on web servers running the
Apache Web Server software. When a .htaccess file is placed in a
directory which is in turn 'loaded via the Apache Web Server', then
the .htaccess file is detected and executed by the Apache Web Server
software. These .htaccess files can be used to alter the configuration
of the Apache Web Server software to enable/disable additional
functionality and features that the Apache Web Server software has to
offer. These facilities include basic redirect functionality, for
instance if a 404 file not found error occurs, or for more advanced
functions such as content password protection or image hot link
prevention.
Basically .htaccess is giving you permission to edit the configuration of Apache Web Server. You will gain permission using .htacess if mod_rewrite is enabled in Apache. I will not write what that 4 basic line in .htaccess can do in codeigniter because you can find it in google. this link can give you some nice basic info.
Now the main issue is .htaccess is not working in your other hosting. This is possible because a few reason :
For some reason, mod_rewrite is disabled in your Apache Web Server. If your hosting is VPS or DS it's possible you are didn't configuring it yet. Someone already ask how to enable mod_rewrite, you can go to this link. If you are using Shared Hosting, ask your hosting to enable mod.rewrite in your host. You can check if mod.rewrite enabled or not in your hosting following this link. Or you can simply check with <?php phpinfo(); ?> and check in "Loaded Modules" for mod_rewrite exist or not. Example in this image.
You are not using Apache as Web Server. There are others Web Server as NGINX and lighttpd. You should ask your server administrator what Web Server are you use currently. I dont have any experience using NGINX and lighttpd so i cannot give you any help in that. But as far as i know .htaccess code is different in APACHE, NGINX, and lighttpd. You can try to convert .htaccess apache code to nginx code in here or here. For converting .htaccess to lighttpd unfortunately, i cannot find any online converter but there are official guide here and here
Well for the complete tips sake i will write this. It's possible you are not configuring codeigniter to not use index.php. In config file, empty configuration for index_page. and give Base_url your domain name. $config['base_url'] = "yourdomainname.com"; $config['index_page'] = '';
I hope this clear your confussion why your .htaccess didnt work.
As you mentioned here, on localhost your code is working fine but when you moved it over live server it causes 404 error. There might be few cases you need to check:
Step 1: Check mod_rewrite is enabled or not in your Apache configuration
Step 2: Remove index.php in codeigniter config as #geordy suggested
You can check it by
<?php
echo 'Test'; die;
?>
in your root index.php. It ensures your all requests should go through this files else Codeigniter framework would not work properly.

Beginner php.ini and .htaccess

RewriteEngine On
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?l=$1 [L]
I use this code in .htaccess to shorten url on my old shared hosting server.How I write this to use in php.ini on new vps server?
I'm begineer.I use CWP on my vps.
Please answer!!
You should not put this to php.ini! It's about Apache web server, not about PHP.
Create .htaccess file in your website root and put your rules into it.
Here you can find a manual for Apache installing and configuring

Why is my htaccess not working on my web server (but it works fine locally)?

I have the following htaccess file for my website, http://academy.young1.org.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
However, although it is working perfectly on my local server (localhost) and redirecting to the correct pages despite the '.php' extension not being present in the URL, it is not doing this at all when I load it up to the web server. It is currently stored in the same ftp subdirectory as my main php files, ftp://ftp.young1.org/academy.
I have tried rewriting the httpd.conf file in my Apache directory:
<Directory / "ftp://ftp.young1.org/academy/">
AllowOverride All
Require all denied
</Directory>
but to no avail. Is there a setting I have to change somewhere or additional code I have to place in to make it work? I am currently using a Xampp system on easyspace hosting.
Thanks,
Regards,
Robert Young
First check is you mode_rewrite module is enabled and confirm url rewriting is possible in your server. I hope you have a shered server,if its from godaddy url rewriting is not possible in my knowledge, please contact your customer service. because i have the same issue.
This link will really help you to correct your htaccess
http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/

How enable mode_rewrite in windows server 2008 r2 (with php installed)

i have windows server 2008(r2) and i installed php and mysql using with Web Platform Installer in that windows.
it seems everything is ok about php and mysql.
now i want to install http://www.phpfreechat.net/ in my server.
after installation i got this error :
mod_rewrite must be enabled server side and correctly configured. "RewriteBase" could be adjusted in server/.htaccess file.
as you know .htaccess file is for linux servers.
what this error mean and how can i fix it?
i think in my server php is working under iis and there is no appache in my serevr, so how can i bypass that error?
i changed the wwwroot permission to EveryOne with no help.
also when i open wwwroot with cuteftp i can not find any permission by right click on every file (properties)
EDIT:
there are some folders in that project like client - server - etc
in server folder .htaccess is like this :
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /path/to/phpfreechat/server
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<Limit OPTIONS GET POST PUT DELETE>
Order allow,deny
Allow from all
</Limit>
thanks in advance
mod_rewrite is for Apache servers. Here you can see how to use rewrite rules for IIS using the URL Rewriting Module.
You should really read this document on how to create new rewrite rules. I don't know whether it supports .htaccess or not, but I don't think so. Just follow the official documentation.

Categories