How to change directory from: articles/article.php to: articles/article/ (without filename) Is it directory with hidden index.php or something else? I think it's related with .htaccess but I'm not sure. How can I do this?
-
3Google "mod rewrite htaccess" - 1st result > http://www.branded3.com/blogs/htaccess-mod_rewrite-ultimate-guide/ - one of *About 304,000 results (0.30 seconds)* – Funk Forty Niner Aug 10 '14 at 04:21
-
If you're using a framework like Zend or Code Igniter, most have a way of customizing routes. – The Unknown Dev Aug 10 '14 at 04:22
-
It's seems you're looking for URL Rewriting, maybe helpful if checking This: http://stackoverflow.com/a/16389034/3878932 – Moshtaf Aug 10 '14 at 04:22
-
You may want to make your title a little more descriptive. Also, all five of the tags/keywords you chose have nothing to do with what you're trying to solve. – TheCarver Aug 10 '14 at 04:54
2 Answers
You can use .htaccess to remove the file extensions as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Where it says .php change that to your file extension. Keep in mind that for example if your file is about.php and you have a folder called "about", it won't work.
The route I see most people use is to have a huge directory of folders and index pages, that will work just fine, however search engines will have a hard time indexing your site.
This is a really popular question, probably didn't need to come here to ask haha

- 260
- 5
- 19
Option 1 - Mod rewrite htaccess
You're probably looking for mod rewrite with an htaccess file. With this, you can point these types of URL's:
mydomain.com/articles/article/1001
mydomain.com/articles/1001
mydomain.com/1001
to this:
mydomain.com/articles/article.php?id=1001
Option 2 - Using index.php
Alternatively, you can create a sub-directory in articles
called article
and rename article.php
to index.php
- this will allow you to use the following:
mydomain.com/articles/article
Option 3 - Hide PHP extensions
Or turn off PHP file extensions in PHP configuration file, which would also give you:
mydomain.com/articles/article