Question:
How do I get my site to read as "site.com/page" instead of "site.com/page.html"?
anonymous
2008-12-06 20:34:32 UTC
I want my site to not show the file extension, so it is easier to remember and easier to type, without having to say .php or .html. How do I do that??
Three answers:
anonymous
2008-12-06 20:37:34 UTC
make a new folder called page in your directory, then rename page.html in the page folder to index.html, by default when you navigate to site.com/page/ , the index page is shown.



Sorry, i typed fast.
anonymous
2008-12-07 05:26:03 UTC
First, you must check that htaccess overrides are permitted in your server space - they usually are but may not be. If you can use htaccess with your site then either create an htaccess file in your site root (if one does not already exist else add to the existing file) and add these Apache directives:



RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^(.*)$ $1.php



Replace php with html if you are removing the html file extension.



If you already have pages indexed in search engines or linked to from external web sites, replace the last rewrite rule with this:



RewriteRule (.*)\.php $1 [R=301,L]

This will ensure that any incoming links pointing to the page+file extension will be correctly redirected to the page without the file extension and will inform browsers and search engines that the URI has changed.



Note - don't remove the actual file extension from your file names. Files are files, URI's are URI's and your files still need the extension even when this doesn't display in the URI.
anonymous
2008-12-07 04:56:55 UTC
In addition to the previous suggestion of using directories to accomplish this task, you can also use a rewrite rule to accomplish the same, something like this:



RewriteEngine On

RewriteRule ^(.+)([htm(l)?]|[php]) $1 [L]



This rule would work for Apache's mod_rewrite and most Microsoft IIS implementations of URL rewriting that supports regular expressions.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...