I have this in my htaccess, now it this is for removing the .php extension. My subdomain is http://example.domain.com and each time htaccess tries to look for .php and shows up 404, I’ve trying to find out how to make this work as well add trailing slash http://www.domain.com/example/ when ever going to the subdir.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Your code is fine (except for the No Case flag) for adding a .php extension to an extensionless filename. Apache will add the / to give you domain names but you will also need to check for !-d for the PHP extensionless, too. If you “merely” want to add the trailing / for directories, try:
I see, the rules given seems to block me from my site. The above code works, but tries to add “.php” to a directory subdomain and it gives off a 404 error. As per the trailing / can it be added to files .php or the files must be created within a folder of the same name?
Do you know where I could possibly get a list of commands? Thanks.
The rule above was designed to add a trailing / to a directory URI.
Why would anyone want to add a trailing / to a file name? This is both illogical and contradicts the functioning of the server. It IS possible, however, if you use MultiViews (which I loathe).
As for a good tutorial, I’ve had acclaims from many SP members for the one linked to in my signature (and you know where to find me if you have questions about the content).
… simply says that, if the URI is a directory request and there is not a trailing /, add the trailing /. There is NOTHING there which would block anything.
So, please post your full .htaccess and test URIs.
Rémon is (pedantically) correct as you don’t want to redirect to a directory which does not exist. The code functions in the manner he described.
Your code says: If the {REQUEST_URI} is not for an existing file, add .php to the URI and serve that (REMOVE that No Case flag - URIs are case sensitive!!!). I do not know how you added a trailing / with this code.
Because your two cases are different (one is add .php file extension - to a non-file, i.e., DIRECTORY, name!?! - and the other is add a trailing / to a directory). As I had stressed in another current thread, your first step should have been to define each task for mod_rewrite, convert each of those tasks into pseudocode (to see where conflicts might exist) then into mod_rewrite code. You have skipped the first step and your results show it. Relax, think about each task in detail THEN get to coding.
I use apache.org as my reference for all things mod_rewrite. They’re generally readable but do get into some techno-babble but well worth wading through.