I`m trying to hide my php files extension in my hosted server.i add following code segment in .htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
but when i try, it is not working. also i tried to do the same thing in my localhost.it is also not working properly.
so do i have to make any other changes to work on it?
The best solution for this is to first:
1. Convert all your .html files to .php
2. Make a .htaccess to hide all known .php extensions
E.g:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
NOTE: If you already have the RewriteEngine on command on top of your .htaccess file, no need of writing it when making new commands.
This method yet is ineffective because when you access localhost/login.php, it would redirect to localhost/login.
So you must do that with php in the individual files!.
Use
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Related
my website is,
http://localhost/mywebsite/page.php?id=123
using .htaccess i changes my url like this
http://localhost/mywebsite/newpostof2016
but i want like this final url
localhost/mywebsite/newpostof2016.php
current using .htacces code is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)$ page.php?id=$1
does this work? It should add .php to all files even if they arent php files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]
N.B. there are many reasons as to why you wouldn't want this behavior. I can't think of a case where this would benefit UX
This rule should do it.
RewriteEngine On
RewriteRule ^mywebsite/newpostof2016\.php$ /mywebsite/page.php?id=123 [L]
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]
Because all my files are php I have removed php extension with this .htacess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
So I have this URL:
http://example.com/live/kanal/some-title-1
http://example.com/live/kanal/some-title-2
http://example.com/live/kanal/some-title-13
http://example.com/live/kanal/some-title-45
http://example.com/live/kanal/2some-title-333
etc ...
I want to hide kanal/ from url, to get URL like this:
http://example.com/live/some-title-1
http://example.com/live/some-title-2
http://example.com/live/some-title-13
http://example.com/live/some-title-45
http://example.com/live/2some-title-333
How can I achieve this using mod_rewrite?
I used online generators for doing the rewrite rules but none can remove a piece of text from the URL. Also I made search on this forum, and I found some posts about mod rewrite directory but I have issues when pasting in my .htacess code.
You can use this code in /live/.htaccess:
RewriteEngine On
RewriteBase /live/
RewriteRule ^(?!kanal/)(.*)$ kanal/$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Make sure there is no .htaccess in kanal/ sub-directory.
How can I remove .php extension from php files
htacess file
RewriteEngine On
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
any help is much appriciated, Thanks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ $1.php [NC,L]
If you go to example.com/test/ it will load example.com/test.php
For hat you should define an entry point.
Then you can rewrite your URLs to a parameter of a specified file in that case the index.php.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ index.php?url=$1 [NC,L]
Then you can filter that parameter in your script and show the correct content.
You have an URL something like:
www.example.de/test-test
Then everything is rewritten to your index.php. Other possibility if you rewrite to an existing file. You can do something like this:
RewriteRule ^(.*)/?$ $1.php [NC,L]
Then you fetch everything behind the slash and call an existing PHP file.
Remove .php extension with .htaccess
I am trying to remove the ".php" on my website. I have changed the .htaccess file based on the documentation provided in the dreamhost wiki to the following:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
However, this does not work on the site. For example this code does not work:
link
It shows the following error:
Not Found
The requested URL /jimmyvosler.com/public/about.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This works (but still displays the .php at the end, which is what im trying to fix):
link
I don't understand what is causing this, especially since the error even points to the correct place. Is there a setting I need to check on my admin tool?
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Here is the solution for anyone else that has the same trouble. I added this to my .htaccess file. This solution came from dreamhost support and was linked from this website: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Try this:
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]