extension less php site with forward slash - php

I have a problem for my php website, i do some research and my url look like this www.example.com/about, that's a correct output but i want to add extra forward slash so the url look like this www.example.com/about/ same with the wordpress behavior.
my .htaccess file:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
thanks.

Related

How do I use .htaccess to hide a folder and extension?

I want to be able to type “example.com/page” in the url and my browser to load “example.com/folder/page.php”
I literally looked at 10+ video tutorials and 20+ pages on how to do this and none of them are working properly. I can't include everything I've tried because I've tried so many with none of them working.
An explanation would also be helpful. Thanks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^folder/(.*)$ http://www.example.com/$1 [L,R=301]
Try this
# it may also need to set mutliviews
Options +MultiViews
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless URL
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]
# Resolve .php file for extensionless PHP URLs
RewriteRule ^([^/.]+)$ $1.php [L]

how to change php extension into aspx extension using htaccess

I'm new on php programming and i'm customizing an CRM base on PHP. I want to change the .php extension in .aspx, whether the php script is in the root file or sub directory, the .aspx should show up.
Here is my URL
I want to change THIS:
http://localhost/edev/pages/UI.php?operation=req
Into:
http://localhost/edev/pages/UI.aspx?operation=req
the code that i have tried
.HTACCESS
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://localhost/test/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://localhost/test/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
Let me know if you have any question according to this question. Thank You :)
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.aspx$ $1.php [L]

htaccess Remove trailing slash, force HTTPS, hide php extension

I've got an SSL certificate, and I need to force https on my website.
Additionally, I need to remove trailing slashes, and hide the .php extension from files.
This is what I have so far, but it's causing too many redirects:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ https://hellorufus.com/$1 [R,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ https://hellorufus.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# 404 Error Template
ErrorDocument 404 /404.html
I've found a number of similar questions, but when I try to piece them together for my own needs, I end up with too many redirects again!
This is a version with a few corrections that appear plausible:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ /$1 [R=302,L,QSA]
# Redirect external .php requests to extensionless url
RewriteRule ^(.+)\.php$ /$1 [R=301,L,QSA]
# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [L,QSA]
# 404 Error Template
ErrorDocument 404 /404.html
Not sure if that already solves your issue. To be certain we would need some specific request URL that generates an endless rewrite loop.

No access to files in subfolders when removing extension in .htaccess

I want to access some php files which are located inside some subfolders. I'm using a .htaccess file, which removes all the .php extensions.
Here is the file:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.net/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.net/folder/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
I have to say that I just copied this .htaccess file from a tutorial, because I have no experience in this area.
So a quick example: I can access www.example.net/folder/myphpfile.php , but I get a "file not found" error when I try to access www.example.net/folder/anotherfolder/myphpfile.php .
But it works when I delete the .htaccess file.
Can someone help me with this. Thanks!
Have it this way:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \s/.+?\.php
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

Hide PHP extension from second segment of url

I am using one htaccess code (Core PHP) to hide php extension from url and its working great but not true with second segment of url
for example if url is http://www.abc.com/somepage than my code is running great but if url is
http://www.abc.com/xyz/sompage than my code will fail.
here is my code of htaccess
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.abc.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.abc.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $2.php [L]
Please help me to find out hte solution that no matter how much segments are there but it should take last segment as a php file
Thanks in advance
Try to add:
RewriteCond %{HTTP_HOST} !^www.abc.com/xyz [nc]
RewriteRule !^(.*)$ !http://www.abc.com%{REQUEST_URI} [R=301,L]

Categories