How to rewrite an url without beening displayed the file extension - .htaccess

How i rewrite url, using htaccess , i have tryed like this :
RewriteRule ^file$ file.php [L]
i don't want to be displayed the file extension
i want to rewrite url like this :
http://example.com/file.php into http://example.com/file

RewriteEngine on
RewriteRule ^file$ /file.php

Related

how to redirect url with parameters using htaccess file

I'm trying to change my url using htaccess file.
my url is : http://localhost/shasi/payment-result?Authority=000000000000000000000000000023436395&Status=NOK
and i want to redirect my page to this url : http://localhost/shasi/payment-result/Authority/000000000000000000000000000023436395/Status/NOK
How can i do this ?
RewriteCond %{QUERY_STRING} ^Authority=([0-9]+)&Status=([^/]+)$
RewriteRule ^payment-result /payment-result/Authority/%1/Status/%2 [R=301,L,NC]

.htaccess - How to Override Url Even If someone Puts the .PHP after the filename

I have created the .htaccess file to rewrite url for .php
Before creating the .htaccess files
Url was like : www.xyz.com/contact.php
After creating the file
Its like : www.xyz.com/contact
But if someone writes in the url
www.xyz.com/contact.php
The .PHP extension is displayed hoe to hide it even if someone enters it manually
the following code will remove .php even if users write it :
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?/] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]

MAMP htaccess rewrite

I'm using a .htaccess file for the first time with MAMP servor, and I'm trying to do something simple :
I want this link : http://localhost:8888/My_app/ redirect on : http://localhost:8888/My_app/Pages/ .
I did these on .htaccess file, located on /Application/MAMP/htdocs/My_app/ :
RewriteEngine On
RewriteRule ^$ http://localhost:8888/My_app/Pages [L,R=301]
This work, but it simply redirect the user. I want to see the first url http://localhost:8888/My_app/ and not http://localhost:8888/My_app/Pages in my browser, like a 'pointer' on this page, is it possible ?
Thanks !
Updated -
So it work great with this code :
RewriteEngine On
RewriteRule ^/?$ http://localhost:8888/My_app/Pages/ [L]
But I have forgotten something in my question, how to do the same for each file in this folder ? If I want http://localhost:8888/My_app/dashboard.php pointed on http://localhost:8888/My_app/Pages/dashboard.php ?
You can just use this rule:
RewriteEngine On
RewriteRule ^((?!Pages/).*)$ /Pages/$1 [L,NC]

how can i remove user folder from url using htaccess

How can I rewrite the URL www.example.com/user/xxxx into www.example.com/xxxx using htaccess ?
I tried:
Redirect /user / user/xxx
But, it does not work.
RewriteEngine on
RewriteRule (.*) / user/$1

Url rewriting behaviour

I currently have a simple website with a couple of .htm pages, and im trying to use .htacess mod rewrite to remove the .htm extentions.
I have a folder with 4 .htm pages, the index link to the other 3 by href, when I access click the link the url changes from www.domain.com/ to www.domain.com/page.htm, shouldn't it hide the .htm?
Does having url rewriting envolve having each page on a folder?
You should be doing this:
use URI's like www.domain.com/page in your index file:
and these rules in your .htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(\w+)/?$ [NC]
RewriteRule ^ %1.htm [L]

Resources