.htaccess on GoDaddy not working - apache

I have web hosting in GoDaddy.
Call it: http://example.com
I have this below .htaccess
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]
What I want is, when I open http://example.com/about.php will be http://example.com/about <-- without .php extension.
I tried to upload it to the hosting, but it always show error the file not found.
*Are we need to wait for long time to godaddy update the .htaccess?

To remove .php from pages:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php [NC]
RewriteRule ^ %1 [R=301,L,NC,QSA]
and then, internal redirection to php pages:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f [NC]
RewriteRule ^.*$ $0.php [QSA,L]

Related

.htaccess file not working properly in ionos. My website- https://rentocure.com

I want to have clean link like- https://rentocure.com/doctors/rc635502e5e9376 instead of https://rentocure.com/doctors.php?uid=rc635502e5e9376 (U can go through my website). I have the following code in localhost
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)/$ $1 [L,R=301]
RewriteRule ^/?home/([^/]+)?$ "index.php" [L,QSA]
ErrorDocument 404 https://rentocure.com/404/
RewriteRule ^doctors/([^/]*)$ doctors.php?uid=$1 [L]
RewriteRule ^hospitals/([^/]*)$ hospitals.php?uid=$1 [L]
which is working fine in localhost but not in ionos apache server so I changed it to the following:
Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#Redirect to SSL Secured Page
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://rentocure.com/$1 [R=301,L]
#Removing File Extension .php and adding trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
#Custom 404 Page
ErrorDocument 404 https://rentocure.com/404/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^doctors/([^/]*)$ doctors/?uid=$1 [QSA,L]
But still it is not working kindly check my website and give me the solution. For the one whose solution will work for me will get assured cash reward from me.
Expecting solution through .htaccess code.

How can I get in one spesific folder?

I have made clean urls in .htaccess file, but after that I dont get Access to a spesific folder. How can I get Access to /folder/?
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)$ index.php?side=$1 [QSA]
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?side=$1 [QSA]
RewriteRule ^([a-z]+)\/([a-zA-Z0-9]+)\/?$ index.php?side=$1&id=$2 [NC]
RewriteRule ^rss/feed/([a-zA-Z0-9]+)\/?$ index.php?side=feed&id=$1 [NC]
You can use the following :
Options +FollowSymLinks
RewriteEngine On
##-if an existent dir or file is requested, serve it immideatly##
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
########
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?side=$1 [QSA,L]
RewriteRule ^([a-z]+)/([a-zA-Z0-9]+)/?$ index.php?side=$1&id=$2 [NC,L]
RewriteRule ^rss/feed/([a-zA-Z0-9]+)\/?$ index.php?side=feed&id=$1 [NC,L]

How to get htaccess to load page without file extension

I have searched around and tried a few different things, with no luck.
I am trying to load this page http://SERVERNAME.com/get.php when I use the url http://SERVERNAME.com/get
Here is what I have in my htaccess now:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
I have tested to make sure my htaccess file is being read by intentionally breaking it and getting a 500 error.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{THE_REQUEST} ^(?:GET|POST)\ /.*\.php\ HTTP.*$ [NC]
RewriteRule ^(.*)\.php$ $1 [R=301,L]

htaccess rewrite rule for backend/frontend app

I have a yii app that has separate back end and front end. I am trying to make friendly url.
I have tried some online tools but could not get it correct
So I want this url
http://mydomain.lc/abs/admin/some/crazy/urls (for example
some/crazy/urls can be admin/index)
will be rewritten to:
http://mydomain.lc/abs/backend.php/some/crazy/urls (because this
url works directly)
And I have also front end site but they are both in the same project so they share .httacess.
the rule for .htaccess for front end is:
this url:
http://mydomain.lc/abs/some/crazy/urls (some can not be admin
here, so we can differentiate btw fron and back end)
should be
http://mydomain.lc/abs/index.php/some/crazy/urls
I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^abs/admin/?(.*?)$ abs/backend.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!abs/admin\/)(.*?)$ abs/index.php?url=$1 [QSA,L]
</IfModule>
the above script is not working.
Root is under abs folder and .htaccess in the root
You do not have to change anything except RewriteBase / to RewriteBase /abs
RewriteEngine On
RewriteBase /abs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/?(.*?)$ backend.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!admin\/)(.*?)$ index.php?url=$1 [QSA,L]
I guess the problem is with the RewriteBase.
You may try this in the .htaccess file in /abs directory:
Update according to last OP comment: this one is correct: backend.php/some/crazy/urls
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /abs
# Backend admin
RewriteCond %{REQUEST_URI} !backend\.php [NC]
RewriteRule ^admin(.*) /backend.php/$1 [QSA,L,NC]
# Frontend
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteCond %{REQUEST_URI} !admin [NC]
RewriteRule ^(.*) /index.php/$1 [QSA,L,NC]

Redirect .php to extensionless and make url without .php

I dont really know too much about Rewrite in apache, but there is problem with my .htaccess file.
the original .htaccess is
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_.]*)$ /profile.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Unless directory, remove trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.domain.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.domain.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
ErrorDocument 404 /404.html
The first rewrite is for vanity url, another is redirecting non www to www and after that .php to extension less and redirecting .php file to extension less,
Problem i am facing is, if i request www.domain.com/ttt.php and if ttt doesn't exist then it redirects me to http://www.domain.com/profile?id=ttt.php
Also, i want the rewrite to be for php files not other type, Say if i have ttt.png file and i open www.domain.com/ttt it opens the image rather than showing 404 error.
Similarly happens with other type of files. It opens .txt file first if the names are common.
Thanks for any changes to this, seriously i don't want to mess my site.
This rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_.]*)$ /profile.php?id=$1 [L]
Needs to be at the very end.
And this rule:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Needs the [L] flag and needs to replace RewriteRule ^([^/.]+)$ $1.php [L]. Then you can duplicate this one and replace .php with .png, and .txt and every other extension you want to handle, in the order of preference:
Options +FollowSymLinks -Multiviews
RewriteEngine on
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Unless directory, remove trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.domain.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.domain.com/$1 [R=301,L]
# add extension if the php file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# add extension if the png file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.png -f
RewriteRule ^(.*)$ $1.png [L]
# add extension if the txt file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.txt -f
RewriteRule ^(.*)$ $1.txt [L]
# add extension if the html file exists:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
# etc.
# finally, route to profile.php if all else fails
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_.]*)$ /profile.php?id=$1 [L]
ErrorDocument 404 /404.html
Since you're routing to profile.php, in the profile.php script, you'll need to redirect to /404.html if the id param doesn't exist (meaning the URI that got routed needs to be a 404).