hello my friends :)
I'm new to web dev so ive started learning PHP.
i have a couple of questions...

1. Can i change the default .php extension to .whatever ?
2. Can i change something.html to something.whaever extension? in Apache Mod rewrite? i mean SEO. i want to make fake extension that can show like this:

index.jsp
whatever.jsp etc...
i know im using PHP but would it be possible change to .jsp extension? ive installed XAMPP on my local PC and I edited Apache.conf file and added index.jsp next to the AppDirectory. so shouldn't it allow .jsp extension?

if so please explain it in detail as much as you can.
anyhelp would be much
appreciated

Dani AI

Generated

Both of the routes mentioned in this thread are workable. As pointed out, either tell Apache to treat a nonstandard extension as PHP (so files with that extension are parsed by PHP) or keep the real .php files and expose different public URLs via redirects/rewrites (as hinted). Important point: ".jsp" is historically a Java/JSP extension; mapping it to PHP just changes which handler runs on the server — it does not make the file a Java/JSP page. On modern setups the exact handler name/technique depends on how PHP is installed (mod_php vs PHP-FPM/FastCGI), so configuration must match the PHP delivery method in use.

An internal rewrite keeps the .jsp address visible while serving a .php file (no visible redirect). Example for an .htaccess or vhost:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_-]+)\.jsp$ /$1.php [L,QSA]

Use an external 301 redirect when the intent is a permanent public URL change (SEO/crawlers).

If mapping the extension to be parsed as PHP, do it at the server config level with a handler mapping (replace the placeholder with the actual PHP handler string found in phpinfo()). Example pattern:

<FilesMatch "\.jsp$">
  SetHandler YOUR_PHP_HANDLER
</FilesMatch>

Operational notes: edits to httpd.conf or the appropriate XAMPP include file must be followed by an Apache restart; mod_rewrite must be enabled and AllowOverride configured if .htaccess is used; check Apache error_log when things fail. For SEO and long-term clarity, consider extensionless or semantic URLs instead of pretending to be another platform (JSP).

Recommended Answers

All 4 Replies

I believe Apache will let you map any extension you wish to a given mime type, but off the top of my head I can't recall which file it is in. Check the docs on mapping mime types.

Take a look at this, perhaps it will help:

There are two ways to do this:

1) Tell Apache to parse all .phpfiles a .xxxfile. Using this method you do not have to change any files extensions or worry about any redirects. To do this, place this code in your httpd.conf file:

AddType application/x-httpd-php .php .xxx

2) Use a 301 redirect to redirect from the .php files to the .xxx files. You can do that by placing this code in the root directory of your website:

RedirectMatch 301 ^/(.*)\.php$ 

tnx a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.