Forum Moderators: phranque
Jim
The first problem with your rule is that it contains nothing to prevent a request for index.php from being rewritten to itself. This sets up an 'infinite loop' -- one sure cause of a 500 error.
One of several possible cures --and the most efficient-- is:
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond $1 !^index\.php$
RewriteRule ^([^/]+)/?$ /index.php?$1 [L]
In case it's not clear, mod_rewrite in .htaccess is recursive -- as it must be to enforce access restrictions and to detect further rewrites on previously-rewritten URLs. Therefore, recursion must be explicitly prevented.
Jim
This is the link that you should put on your pages, and this link will be displayed in search engine results.
If that's not the case, then perhaps you're going about this (or possibly thinking about this) backwards.
Facts:
So maybe it's time to back up a step and tell us what you want to do:
What URL do you want to link to on your page? (this URL will appear in search results)
Please confirm that the file that requests for this URL are to be rewritten to is /index.php in the root directory of your domain.
Be aware that by introducing a virtual directory into the URL (which is what you are doing if you append a slash to that friendly URL and type it in as "example.com/home/"), you will be changing the base directory that the browser will use to resolve page-relative links on your pages. If you choose to use the trailing slash in your links (which I strongly recommend against in this case), you will need to change those page-relative links on your pages to server-relative links or to canonical links. That is, you'll have to
use <img src="/images/logo.gif"> or <img src="http://www.example.com/images/logo.gif">
instead of <img src="images/logo.gif">
BTW, the thread I linked to above ("for all the details") describes all of this, and I hope you have read it... There are no "safe" short-cuts with this stuff, and if you make one little typo, you place your site's search ranking at risk. Please research before coding...
Jim
You didn't say you didn't want that, and the rule you posted (with the correction I provided) will do that.
18 posts on, and no progress... As I said, you need to stop coding, and define what you want to do precisely before proceeding to code.
Jim
Again, note that I said URLs, not filenames, and the place to look for info to build this "map" is in the source code of your HTML pages.
I suspect that you'll be able to "boil down" that map to a simpler form; For example, it may be that you only want to rewrite URLs to your script if they do not end with a filetype. But we cannot tell you that, you have to tell us, since only you are familiar with your sites' URL-space, with how it works today, and with how you want it to work...
The reason for my first reply in this thread should be fairly obvious by now, but the fact it, you're going to be getting a lot more familiar with how servers work, and this will make things far easier in the future.
Jim
[edit] Fickst mi speling errurs [/edit]
[edited by: jdMorgan at 7:47 pm (utc) on Nov. 12, 2008]
Here, I'm going to suggest this because I'm off to take care of business for awhile:
Options +FollowSymLinks
RewriteEngine on
#
# Internally rewrite all top-level requested URLs which
# do not end with a filetype to the /index.php script
RewriteCond $1 !\.[a-z0-9]+$ [NC]
RewriteRule ^([^/]+)$ /index.php?$1 [L]
Jim