Removing .php makes problems with .inc - php

I just removed the .php extension from my website by using the code
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\.php
RewriteRule ^ /%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
But now my login.inc.php makes an error?
How to fix please.

I found out that i just need to make another .htaccess file under the directory of the .inc.php file with the same code and now it works!

Related

.htaccess avoid accessing files with .php after rewrite

I applied a rewrite rule to show my php files without the .php at the end of the file. This is what I have:
##Quitar extensión .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
But the problem I have is that I can access that file with two ways. With or without the .php. For example: mywebsite.com/file.php and mywebsite.com/file both work but I just want the second one to work so I need to add something to my .htaccess file to redirect mywebsite.com/file.php to mywebsite.com/file or show a 404 error. But I think the first option is better.
Is it possible to combine my .htaccess code with what I want? And if so, what is needed to be added?
You can use this rule to remove .php extension
RewriteEngine on
#1)externally redirect from "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,R]
#2)internally map "/file" to "/file.php"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

I can't remove .html, extension

Hi I been searching for a way to get rid of the .html extension and they all say to create a .htaccess file which I have done and have placed the code in the file but it still doesn't work. I'm not sure if I'm saving in the correct area or I've got the the wrong code.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*).html\ HTTP/
RewriteRule .* http://localhost/html/%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /html/(.*)\ HTTP/
RewriteRule .* %1.html [L]
</IfModule>
Hope it will help you.

removing .html URL extension using .htaccess not working

I'm using the below code to remove .html extention form url, but it is not working..
can any one help , where i have to put the .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
I would like to share an understandable, simple way to remove the .html extension from the URL using the .htaccess file. I'm using XAMPP on Windows 10. For me, it's working perfectly. If you want the same result, just follow the steps given below...
For removing the .html extension, e.g. if you want to change mywebsite.com/contact.html to mywebsite.com/contact you have to add the following code inside your .htaccess file:
First of all, create a new file named .htaccess and placed it at your root-directory where your index file is placed.
Now, open this (.htaccess) file with any editor of your choice and write/copy/paste the given code in your file and save it...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Now, if you (any user) will access mywebsite.com/contact in the browser, it will show the content of mywebsite.com/contact.html page.
So, what if any user will access the URL as mywebsite.com/contact.html? this will redirect the user to this mywebsite.com/contact.html page instead of this mywebsite.com/contact which means the user can still visit the mywebsite.com/contact.html page. Don't worry about it. If you want to avoid this, the next step is for you...
To avoid the above problem and for redirecting users to the newly created URL, you need to add some more rules in your .htaccess file. So, open it again and replace your old code with the new one given below and save your file...(You can ignore this step, It's on you...)
RewriteEngine On
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Now, you're all set.
I hope this will fix everyone's problem.
Have a nice day :)
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Finally I Got the correct .HTACCESS code to remove .php extention... :)
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Use this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

.htaccess issue under WAMP server

I'm trying to change some of the url names using htaccess.
ex;
mg_com_tr/index.php to mg_com_tr/home
I tried many different code samples inside my htaccess file, but nothing seems to work.
I never worked with the htaccess file before,so in order to test it, I found some example codes just for removing the ".php" extension.
When I try this code, I'm not getting any errors, but its not removing the .php extension either.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
The only working code I found is this one;
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
This removes the .php extension, however whatever I try I couldn't manage to change
http://localhost/mg_com_tr/index.php
into
http://localhost/mg_com_tr/home
I have a feeling that it has something to do with the path
Both the index.php and htaccess file is located at
D:\wamp\www\mg_com_tr\
try
RewriteEngine on
RewriteRule ^home index.php [NC,L]
or
RewriteRule ^home /index.php [NC,L]

.htaccess Rewrite index.php back to directory where index.php is located

I have a directory of localhost/testing/pages/index.php
How do I redirect user to localhost/testing/pages/ whenever they enter localhost/testing/pages/index.php with index.php extension?
I have tried to use this:
RewriteEngine On
Rewrite %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]
but this does not work.
Thanks!
Try:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php
RewriteRule ^ /%1 [L,R=301]

Categories