htaccess *.php to *.html object not found error - mod-rewrite

I am trying to transform URLs from index.php to index.html, servicii.php to servicii.html and so on.
I wrote in my .htaccess file, which is in my site root the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php$ $1.html [R=permanent]
</IfModule>
?>
But when I follow "Prima pagina" (Home) or "Servicii" (the only 2 pages created on site) it gives me a 404 error
Also, I have the code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /fetesti/
RewriteRule ^(.*)\.php$ $1.html [R=permanent]
</IfModule>
on my local machine, which is XAMPP based. It gives me Object not found 404, and on my Apache log:
file not found [...]/index.html;
I know the rewrite engine is working (I wrote gibberish and it gave me 505 internal server error and made other tests)
What am I doing wrong?

Try just remove [R] permanent redirect, and switch extensions in rule
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php
</IfModule>

Related

Laravel remove public from url on localhost

On production I have domain http://xxxx.com.
In root folder I added .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
</IfModule>
And when I type in the browser: http://xxxx.com it works.
The same .htaccess file I have on my machine. I use XAMPP. And it doesn't work. When I type:
http://localhost:8082/myfolder
I get 404. When I type:
http://localhost:8082/myfolder/public
It works.
What is the difference between url in my hosting and on my local machine?
For the first answer:
this is a screen, maybe I'm doing something wrong (.htaccess is in the root folder), maybe .htaccess in the public folder is wrong:
This should work for you:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule !^public/ public%{REQUEST_URI} [L,NC]
</IfModule>
The problem with your rule is that you're checking this condition:
RewriteCond %{REQUEST_URI} !^/public/
Which actually checks for URI /public from web root however you have your site inside a subfolder locally. Here RewriteRule !^public/ will check if public/ is not there at the start after the current directory context, which will work the same in site root as well in a subdirectory.
Similarly for rewriting also make sure you don't use / before public/ to allow it to use a relative path.

Why my .htaccess in codeigniter is different

All of my .htaccess in codeigniter like this
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
But all tutorial .htaccess are like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I need help to remove index.php url in codeigniter.
Why should I replace all code .htaccess like tutorial said ?
Should you replace all code .htaccess like tutorial said ?
Yes! just in the root directory of your CodeIgniter project.
Why?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The CodeIgniter documentation says that by the rules given in .htaccess file, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.
without these rules, for example, you'll have to access your login page like this
http://yourdomain.com/index.php/<controllerName>/login
with the rules in .htaccess file it's
http://yourdomain.com/<controllerName>/login

500 error after moving site on PyroCMS (CodeIgniter) to other server

I just moved old site of my client to some test server.
The site is on PyroCMS.
I've changed database settings in aplication/config/database.php and changed base_url in aplication/config/config.php to my test site URL.
Unfortunatly site is giving me 500 error and I don't have any error logs to see what else is to change.
Where I have to do changes to site run?
My .htaccess looks like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /wherever/pyro/is
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(application\/cache|codeigniter|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I use PyroCMS for almost all my clients and the same issue is in the default .htaccess file.
Try to remove:
Options +FollowSymLinks
And try to add:
Options +symlinksifownermatch -Indexes
Options -MultiViews
Many hosting disable +FollowSymLinks for security reason.
Make sure to set 775 permission to:
system/cms/cache
system/cms/logs
addons
uploads
assets
Also make sure to set your env to PYRO_DEVELOPMENT to see all the errors in this debug phase.

Silex 500 error

index.php
use Silex\Application;
require_once __DIR__ . './vendor/autoload.php';
$app = new Application();
$app->run();
htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
visiting
127.0.0.1/index.php
I get
500 internal error.
Any solutions please?
Your htaccess files should not be named .htaccess.php but just .htaccess.
Then make sure every files have the good rights (apache has access to it).
Be also sure that mod_rewrite is enabled.

mod_rewrite one url string

Can somebody tell me how to get mod_rewrite to rename this:
our-work-section.php?id=3&title=something
to
our-work-section/something/3
Right now my .htaccess is in directory C:\workspace\www\brown, My vhost is setup for http://workspace/, So I did a RewriteBase below. I currently Have:
RewriteEngine On
RewriteBase /www/brown/
RewriteRule ^/our-work-section/?$ our-work-section.php?id=$1 [NC,L]
My error log isn't saying anything, and the page doesn't do anything. I've tried toggling slashes / here and there.
Try this one
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(our-work-section)/?$ /our-work-section.php?id=$1 [L]
EDIT
This one will work. I tested it
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(our-work-section)/([^/\.]+)/?$ /our-work-section.php?id=$1 [L]

Resources