mod rewrite - img paths without extensions - php

I am using mod rewrite to strip URL of the .php extension, but the client wants me to go even further and strip of extensions all src paths in <img>. Is this doable via .htaccess, or maybe php? The only way I can think of now is JS but he wants it server side.

Add a .htaccess file with the following line:
Options +MultiViews
Then you can access the files within a directory without the extension, as long as your filenames are unique it should work OK.
The .htaccess file should be placed at the lowest level within your file structure that you want this behaviour to occur.
This will work for all extension!

Related

How can I remove .php extension while using ISPCONFIG 3?

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)

Running php file by avoiding extension .php in the url without using .htaccess

In my Localhost:
Without using .htaccess, I created a folder named test and a file test.php.
I can run the file from url http://localhost/test/test
In my amazon server with cpanel:
I put the same folder with that file but displays internal server error after checking the url http://example.com/test/test
I tried:
Changing the Allowoverride None to All
enabling mod rewrite
This is actually for a large project. But using a test in this case.
It is possible to rewrite URLs without an htaccess file. That's because you can also use rewrite rules in the Apache configuration files. In a VirtualHost block for example. I guess your localhost is set up that way, so take a look in those server config files.
For your amazon server to work, you either can work with an htaccess file (easiest way) or you can put those rules in the server config files.

How do I allow php files to be loaded with different extension?

I have some PHP files like index.php, contact.php, etc.
I want to name the files with the extension .blah (i.e, index.blah, contact.blah, etc. )
Is there something I can add to .htaccess to get them to load properly?
have a look at your httpd.conf to see how mime type handling is done for .php files, and simply do the same thing for .blah, or use mod_rewrite to change urls ending in .blah to internal redirects to .php through an .htaccess file. Either way, Apache's documentation is going to have all the details.

Accessing PHP Scripts Without .php Extension

How do you configure Apache and/or PHP to be able to access PHP scripts without the .php extension? I have seen PHP scripts executed without the .php extension. I don't mean executing 'script' as a PHP file, I mean executing 'domain.com/script' as a PHP file where 'script.php' exists as a file, but you are able to access it without using the extension. Does anybody know how to configure this?
I AM USING A CPANEL HOSTING!
WHERE TO WRITE THE mod_rewrite? I HAVE A .htaccess file with code # Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working RewriteBase /
Several basic ways:
Use MultiViews. Automatically converts /foo => /foo.php (among other things)
Use mod_rewrite to remove PHP extensions
Use mod_rewrite to direct all traffic to a single dispatcher script, which inspects the URL and performs the proper action by including files / calling class methods, etc.
Generally that's done in Apache via mod_rewrite.
Here's a guide: http://wettone.com/code/clean-urls
Such a rewriting doesn't make too much sense.
If you want (SEO-firiendly|human-readable) URLs, you have to use complete set of rewrite rules, not just removing extension.
Otherwise there would be no point in such a configuration change

Is it possible to have a php file in apache operate without an extension?

I have a file
http://www.www.com/somefile.php
I would like to be able to get to the same file by going to
http://www.www.com/somefile
But I still need
http://www.www.com/directory
to open the file
http://www.www.com/directory/index.php
if, in fact, directory is a directory.
This is a typical LAMP setup with Red Hat and Apache.
Is that possible? If so, how?
An apache rewrite rule will do this for you. The only limitation is you can't have a file named "somefile.php" and a directory named "somefile" (though you can still have directories.
Here's an example rule that supports multiple filenames (just put in in your .htaccess file).
RewriteEngine on
RewriteRule ^(somefile1|somefile2|somefile3) $1.php
Will change /somefile1 to /somefile1.php, /somefile2 to /somefile2.php, and /somefile3 to /somefile3.php.
Look at Apache's ForceType.
If you want to disable the need of file extensions on the url globally on your site, you can also add the following to your .htaccess:
Options +MultiViews
This will enable Content Negotiation. But if you want to match only certain files and/or urls, stick with SoapBox's Answer instead.

Categories