Forum Moderators: phranque
If my file is [mydomain.com...] I want it to appear as [mydomain.com...]
I also want [mydomain.com...] to work when typed as an address or clicked as a link and if someone types in [mydomain.com...] WITHOUT the trailing slash, I'd like the rewrite rule to add it.
Also need to prevent these rules from executing in the /blog/ and /cgi-bin/ directories.
I can't seem to get this from the online docs at [httpd.apache.org...]
Any advice would REALLY be appreciated.
Also, consider the /foo/ is seen as a directory, while /foo is seen as a file. If your extensionless page URLs have an appended slash, you'll likely have more difficulty keeping search engine results clean. There's also the issue that browsers will resolve relative links on page URLs having a trailing slash to a subdirectory with that page name, so all of your on-page links will need to be server-relative or absolute -- or alternatively, you'll need to rewrite all those linked URLs. In short, best advice is to omit the slash if /foo is a page.
Jim
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
RewriteRule ^/.php([^/]+)/?(.*) /$1/ [R]
While foo.php is a file on my server saved as www.mysite.com/directory/foo.php, I just want my URLs to show www.mysite.com/directory/foo/
I read about mapping a file to a virtual directory, but (as you can tell) I'm in over my head.
My thinking is that if we change from php, to say asp or whatever, we can still always have our URLs as /directory/foo/ instead of having to redirect foo.php to foo.asp.
I always add a blank line after each RewriteRule to remind that the next line is treated as being a separate rule. It may need its own prefixed RewriteCond lines.
Be aware of the problems caused when a redirect feeds another redirect. You need to avoid creating a redirection chain of any sort.