I need to remove the .php extension with godaddy hosting - php

I am at a loss, have tried .htaccess which seems to only work on my server, when uploaded to my hosting account, nothing but a big 404 error; I did more research and learned about web.config for godaddy users, still nothing. I am new at using this method, tried numerous rewrite codes, changing the extensions, researching, you name it. Maybe I'm not understanding exactly how to place the files when uploading; I did read threads on here and still I'm missing something.
this is the objective:
site.com/index.php
to
site.com/index
here are examples of what i used to accomplish my goal
.htaccess:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#Fix Rewrite
Options -MultiViews
# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
web.config:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewritePHP"> <match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions> <action type="Rewrite" url="{R:1}.php" /> </rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Related

PHP MVC: htaccess converted to web.config gives me http error 404

I am installed my project done in a PHP MVC framework on a Windows server, but I am having difficulty in making the part of the URLs work.
There are two htaccess, one out of the app and public folders, and one within the public folder.
The first one:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
I converted to web.config using a tool made available by IIS, and it is working.
But the second htaccess does not work.
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
Converted:
<configuration>
<system.webServer>
<rewrite>
<!--This directive was not converted because it is not supported by IIS: RewriteBase /.-->
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/public/index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
Currently giving error 500, internal server error.

Web.config: redirect URLs entered with trailing slash to URL without trailing slash

I have inherited a website PHP website, running on IIS 7.5.
If I go to:
https://www.example.com/page there are no errors, it displays page.php content as expected.
If I go to:
https://www.example.com/page/ I receive a 404 not found error. I'd like this to redirect /page and display page.php content.
I believe it's because the server is looking for a file page/.php (or page.php/ ??), but I need some help with what code to place in web.config to fix this.
If you use iis then add this in web.config To always remove trailing slash from the URL:
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
if you have an Apache Web Server then In .htaccess add this :
RewriteEngine on
#unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
#resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
#redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php /$1 [R=301,L]

how to convert htaccess to web.config

i'm working on a website project, and i have to install the website on the client's server. He has a Godaddy windows account, which doesn't accepts .htaccess files, it uses web.config instead. I dont really know how to write web.config, an i'm in hurry also. I've tried to convert my htaccess with some online converters but of course it doesn't works also. Can you help me out please?
my htaccess:
Options -Multiviews
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME] !-d
RewriteCond %{REQUEST_FILENAME] !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
What the generator generates from it as web.config:
<rule name="rule 1w" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="/-" />
</rule>
<rule name="rule 2w" stopProcessing="true">
<match url="^(.+)$" />
<action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="true"/>
</rule>
Aaand i fixed it in 2 minutes after i posted this question!
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Convert Htaccess to Web for Wordpress

I'm running Apache With .htaccess rules Defined As i mentioned below i have Converted My Wordpress To Windows Server now i want To convert My Htaccess To Web.config is Can someone Do it.
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{HTTP_HOST} (^|\.)kowalski\.com$
RewriteRule ^ http://www..com/ [L,R=301]
RewriteCond %{HTTP_USER_AGENT} ^rogerbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^dotbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^gigabot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteBot
RewriteRule .* - [F]
RewriteCond %{HTTP_COOKIE} !^.*37f298cd809513afc7fbca54ca626089.*$
RewriteRule ^fffsd-cs-post.php - [F,L]
Google seemed to work for me, enjoy.
<rule name="rule 1q" stopProcessing="true">
<match url="^index\.php$" />
<action type="Rewrite" url="/-" />
</rule>
<rule name="rule 2q" stopProcessing="true">
<match url="." />
<action type="Rewrite" url="//index.php" />
</rule>
<rule name="rule 3q" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="/http://www..com/" />
</rule>
<rule name="rule 4q">
<match url=".*" />
<action type="Rewrite" url="/-" />
</rule>
<rule name="rule 5q" stopProcessing="true">
<match url="^fffsd-cs-post.php" />
<action type="Rewrite" url="/-" />
</rule>

Convert HTACCESS to WEB.CONFIG IIS7

I have this .htaccess file. When importing it to IIS via URL Rewrite module it is giving errors. Can someone please help convert it to webconfig.
Thanks in advance
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?action=$1 [NC,L]
</IfModule>
The third condition "is symbolic link" is not supported in IIS rewrite module. If there's no symbolic link implemented, the following rule will be the equivalent:
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?action={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>

Categories