my url is :http://www.example.com/home.php i want to show it when enduser navigates my site as http://www.example.com/home. I know this can be done through .htaccess file.
Following is the htacces file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php
Nothing is happening with the above code in .htaccess file.I want to show entire site pages without .php extension.Can anyone suggest me how to do this
Try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
Related
I'm trying to imitate a routing effect. In my setup the login.php file is located under localhost/session/login.php. I've already found out how to omit the .php file ending but that's not enough for me. Here is my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
This changes the URL to localhost/session/login but what I really need it an URL like this: localhost/login.. The trouble is that I don't really understand how the rewrite above works and I'm getting a lot of mixed answers.. don't know what to do exactly.
Is there a way to have my URL be localhost/login by using some RewriteCondition?
You may use following rules in your site domain .htaccess to enable use example.com/login rewriting to example.com/session/login.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/session/$1.php -f
RewriteRule ^(.+?)/?$ session/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+)/?$ $1.php [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess.
Make sure to put this .htaccess in DOCUMENT_ROOT directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /session/$1 [L]
</IfModule>
Flags used are,
L - Last
This will serve the file at location localhost/session/login.php to localhost/login.php
I'm trying to make a page on my site with the URL of http://localhost/logout/.
I've created the /logout/ directory and the index.php file in that folder, but because I remove the extension of files when I go to http://localhost/logout/ it gives me a 404 error.
To actually get to the page I have to go to http://localhost/logout/index, which I don't want.
How do I fix this?
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Options -Indexes
do not remove the .php extension, add this to htaccess :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I have added .htaccess file to my directory. When I am writing http://lootainment.in/koovs its working. But when I am writing http://lootainment.in/koovs/ its not working. My htaccess file code is following :-
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Make trailing slash optional in your rule and remove directory check condition:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php
Try this,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.|/]+)$ $1.php [NC,L]
At first check your php.ini settings for Server API if your server api is 1)apache, 2)apache2filter, 3)apache2handler or like then only you can use .htaccess file. In htaccess file if your php version is php5 then use <IfModule mod_rewrite.c> block to write this code
try this code
RewriteEngine On
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
this is my htacces file
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
It's work ok but I have one question. If I add to my page files for google in example with .html or .txt i can't see it in browser... How I can change that rule that I could see files from google.
You can avoid rewriting for all files/direcotries:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
This is the code I use to hide php extension
<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
It works perfect but I am getting one problem.
when I want to access blog.php, I simply create link as http://example.com/blog and it works.
I also have file as blog-post.php in same folder so I create link as http://example.com/blog-post.
But It gets redirected to http://example.com/blog with 302 header (I found this in developer tools, on webpage it doesn't shows any error.)
Also I want to make this blog-post search engine friendly like http://example.com/blog/id-of-blog/title-of-blog
So please do tell me how make this possible?
yes it is possible,
try this code with your .htacccess file,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
why are you all using same method. This is alternate method for hide extension. Your file must be like this: about us
Now you add this to your .htaccess file
RewriteCond %(REQUEST_FILENAME) !-d <br>
RewriteCond %(REQUEST_FILENAME) !-f <br>
RewriteCond %(REQUEST_FILENAME) !-l<br>
RewriteCond ^aboutus aboutus.php [L]<br>