How to remove extension .php in subdirectory - apache

I have problem to remove extension .php. For example the url is like
https://www.domainname.net/dev/member.php. I just want to remove the extension .php. can someone help me.

Try this in your htaccess :
Options +Multiviews
then you will be able to access your file without extension.

Here is the .htaccess code snippet that will help you put this code in your .htaccess file:
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# End of Apache Rewrite Rules
</IfModule>

Related

Url-rewriting using .htaccess is not working

I would like my url which is: http://localhost/slide-form/ad_posted.php?title=Cow%20Buffalo%20Gopal-1426356570
to look like : http://localhost/slide-form/ad_posted/title/Cow%20Buffalo%20Gopal-1426356570/
The below is the rule i have added in my htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ad_posted/title/(.*)/ ad_posted.php?title=$1
RewriteRule ad_posted/title/(.*) ad_posted.php?title=$1
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.html
</IfModule>
But I see no changes in my url. Any help is much appreciated. Thanks
Have this code in /slide-form/.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /slide-form/
RewriteCond %{THE_REQUEST} /ad_posted\.php\?title=([^\s&]+) [NC]
RewriteRule ^ ad_posted/%1? [R=302,L,NE]
RewriteRule ^ad_posted/title/(.+)/?$ ad_posted.php?title=$1 [L,QSA]
There are two things need to attention:
Make sure you apache or other web server is already opened rewrite
module.
Check your configuration settings and ensure the directory where
.htaccess file located have the overwrite permission.
Like following settings:

Cake 2.+ on shared hosting - 404 error

Since 2 days I have been trying to get my cake app working (using German 1&1 hosting). The desired address is: http://www.bzalewski.de/k/front. If you open it, you can see, it's there but without images and css. Also this: http://www.bzalewski.de/k/front/art/discover doesn't work (but it does locally with XAMPP. There is no routing, just ArtController --> public function discover()).
I followed the instructions from this article: http://bakery.cakephp.org/articles/tim_m/2007/09/20/500-errors-with-1and1-hosting-apache-1-x
My three .htaccess look like this:
./.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) k/front/app/webroot/$1 [L]
</IfModule>
./app/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /k/front/app/webroot/ [L]
RewriteRule (.*) /k/front/app/webroot/$1 [L]
</IfModule>
.app/webroot/.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /k/front/app/webroot/index.php?url=$1 [QSA,L]
</IfModule>
I would appreciate any help to:
make controllers work (art/discover working)
make images and other stuff in the webroot directory work
Just to mention it: my local XAMPP installation works with standard .htaccess files without any problems.
Try adding this line in the root .htaccess (the htaccess in /k/front/ folder) after RewriteEngine On:
RewriteBase /k/front/
Edit : I did not see that you put /k/front/ everywhere in the htaccess
Then add RewriteBase / with you version of the htaccess
OR add RewriteBase /k/front/ with the default htaccess (without /k/front/ in the RewriteRules )

.htaccess RewriteRule issue on Windows Server

On a windows server we run Helicon Ape for running .htaccess rules and installed PHP. I've below lines in a .htaccess file in root directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)$ test/handle.php?path=$1 [L]
</IfModule>
I wrote the below code in handle.php file.
echo $_GET["path"];
exit;
When I enter any url like this : http://mysite.com/test/test.zip or http://mysite/test/FILENAME.EXT instead printing FILENAME.EXT it just prints handle.php as output!! what's wrong?
Try adding a condition to prevent rewriting handle.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/test/handle.php$
RewriteRule ^test/(.*)$ test/handle.php?path=$1 [L]
</IfModule>

Allow URLs without any extension with url rewriting, like exemple.com/forum

I need to allow urls like http://example.com/forum on my website.
Here is my .htaccess :
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z-]+)$ /$1.php [L]
Currently, I get a 404 error.
If I change ^([a-z-]+)$ /$1.php [L] to ^([a-z-]+).html$ /$1.php [L], and my url http://example.com/forum.html, it works.
I want something like stackoverflow, http://stackoverflow.com/questions
EDIT: It works with WAMP in localhost, but on the website, it doesn't.
What's missing?
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# add .php file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.+) /$1.php [L,QSA]
I have added Options -MultiViews -- can make a big difference on some configurations (possibly your case).
Rule is now also checking if such .php file actually exist. If not -- no rewrite occurs.

add file-ending using .htaccess?

I'm trying to add a file-ending (.kml) to a url using .htaccess but it's not working
The url is http://resihop.nu/kml
I want it to be http://resihop.nu/kml.kml this is what i tried:
RewriteRule ^kml.kml$ kml
Here is my full .htacess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
RewriteRule ^kml\.kml$ kml
You need to tell the server how to handle .kml files. Add this line to your .htaccess:
AddType application/x-httpd-php .kml
(Assumes you want .kml files to be parsed as PHP.)
Edit: Never mind, I just re-read your question and I realise that's not your problem. Just ignore me!
This should work for your case of using your own extension:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\.kml$ /$1.php [NC,L]
Then you could access any file with the .kml extension, such as hello.kml.
Hope this helps.