This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed last month.
Recently i have installed a script. After successfully install. I got in homepage . But then i face the real problem. In navigation or in any link whichever i click i get 404 error. I tried multiple time why getting this. A hour later i found out that, site homepage+ only admin area can be browse. But if i Were to visit other options like settings or sign up/in. Pages i have to manually add .php after urls.
Basically i have lots of this type of internAl code/links. That needs to have php extention after url. So is there any code or tricks to execute .php file without typing it manually? I am on shared hosting. I have access .htaccess file and apache.
Example: site.domain.com/admin/settings = error 404
But
site.domain.com/admin/settings.php
Successfully show settings page.
menu/internal url pointing direct page without .php at the end.
And most importantly i am completely noob in this programing. So any tricks would be great. Although i can edit settings file to add .php after each links, but that is really time consuming+ if i forget to add .php in code. I have to check all of them manually 🥲. Thanks in Advance.
if it's available on your shared hosting platform (it normally is) mod_rewrite could help you here.
See: Removing the .php extension with mod_rewrite
HTH :-)
You have to put *.php in pure php or configure the .htacesse.
Related
I'd need to remove the .php extension from the browser, I used to do it from apache2.conf in the last server I was running the website on, but on this new one I need to use ISPCONFIG3 and I don't know how to use set it to remove the .php extension, since the website was already running on a server which was rewriting the extension the links in the html are all without .php which obviously causes on this new one that pages are not loaded.
Many thanks in advance
You can solve this with mod_rewrite which is available by default in ISPconfig.
As admin you can add these RewriteRules on the Options tab of a web domain. But you can also store them in a .htaccess file together with the php files.
The needed rules are already explained nicely on put links without file extension (.php)
This question already has answers here:
Project Links do not work on Wamp Server
(13 answers)
Closed 4 years ago.
I have a problem with my local WAMP server on Windows, it automatically adds the extension ".php" to the url if the file exists. For example, in the following structure:
+ www
+ files
- main.php
if I call the url http://localhost/files/main it automatically shows me the file main.php.
I was trying to identify where the redirection is but I have not found it. I clarify that I do not have any ".htaccess" file, I have even tried disabling the extension mod_rewrite, I have also searched for a VirtualHost that is redirecting and I have not found anything either.
Removing the Type application / x-httpd-php .php no longer redirects, but of course, it no longer interprets the PHP files.
I need to solve this since it is giving me problems when wanting to rewrite a url with "htaccess" since it adds the extension ".php" to the file.
For example, with the following .htaccess file:
RewriteEngine On
RewriteRule (.*) files/main.php?url=$1 [QSA,L]
And the following main.php file:
<?php print_r($_GET); ?>
When calling the url http://localhost/files/main/param the file main.php runs and shows me the url: files/main.php/param (note that the extension has been added ".php" to the main file).
Does anyone know what may be due and how to fix it?
You need to enable the mod_rewrite and create a virtual host. Follow this tutorial to do it:
https://artisansweb.net/how-to-enable-mod_rewrite/
This question already has answers here:
What is .htaccess file?
(9 answers)
Closed 5 years ago.
I am creating small data entry software using php with ajax code. But I didn't create .htaccess file. I have one doubt. must we create .htaccess file ? why we create .htaccess file. Please suggest.
A .htaccess file is not mandatory.
It has many uses and if there is a specific need, you have to use a .htaccess file. If not, you can ignore it.
For example with .htaccess you can do redirections, you can do authentication with username and password, you can restrict specific directories and many more uses.
In your case, if your needs dont forward you to the use of .htaccess, just dont use one. Although most websites nowadays have at least 1 need that .htaccess covers.
.htaccess is an Apache config file, it works in hierarchical mode, if you load it in a folder, it apply the configuration to all subfolders.
.htaccess is helpful to set timezone, redirect, customize error pages and enable or disable cache.
It is not mandatory however it is recommended its use.
Problem is: I have a website let www.mydomain.com
and it loads index.html, in this file i write some php code but it is not executing
Some days ago i found the solution for executing php in .html file that simply just make a line in .htaccess: (works perfectly in .html files)
AddType application/x-httpd-php .htm .html
In my case above code not working, here problem is that in address bar my link index.html start as mydomain.com so as it is not representing file extension may be thats why above htaccess code not working.
Help me please.
Thanks in advance!
You can actually name your home file "index.php". There just can't be an index.html at the same time (unless editing some configuration stuff).
Perhaps an iFrame would work, which you place in index.html. You can place your PHP code in another page e.g. form.php and load that page in the iFrame. You'd have to do a lot of testing to make sure the functionality is given, as iFrames can cause all sorts of issues, especially, but not limited to, IE.
I have a problem trying to hide .php extension from the url
I have been asked to hide it and because they are on a shared host i don't think i have access to .htacess so is there another way to hide it through a php function that i would call everytime an anchor is being selected?
Is this truly about hiding .php or is it more about having cleaner URLs?
If you truly can't access .htaccess (i.e. your host has this turned off via AllowOverride None) and assuming you also can't have your Apache conf settings updated for your VHost, the best you can do may be
http://example.com/page.php/my/clean/url
By default, Apache will send this URL to page.php even with everything else after it. This is the most common way of creating "cleaner" URLs without access to mod_rewrite.
.htaccess is what you would have access to on a shared server, as opposed to httpd.conf, which you wouldn't.
Put a .htaccess file in your document root with the following
FAIL
If your site stops loading, then you can use .htaccess :)
Of course, ^ that is a joke.