Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it better to handle friendly/clean/pretty URLs with mod_rewrite or a language like PHP?
    text
    copied!<p>I'm developing my first decent-sized PHP site, and I'm a bit confused about what the "right way" (assuming there ever is such a thing) to handle clean/friendly/pretty URLs in the application.</p> <p>The way I see it, there are two main options (I'll use a simplified social news site as an example):</p> <p>1. Use mod_rewrite to handle all potential URLs. This would look similar, but not identical, to the following: </p> <pre><code>RewriteRule ^article/?([^/]*)/?([^/]*)/?([^/]*) /content/articles.php?articleid=$1&amp;slug=$2 RewriteRule ^users/?([^/]*)/?([^/]*) /content/users.php?userid=$1&amp;username=$2 RewriteRule ^search/?([^/]*)/? /content/search.php?query=$1 </code></pre> <p>2. Pass everything to some handler script and let it worry about the details: </p> <pre><code>RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) handler.php?content=$1 </code></pre> <p>Clearly this is all untested "air code," but you get the point. </p> <ul> <li>Is one of these two ways going to be seriously slower than the other? Presumably the mod_rewrite is slower, since I'll be forced to use .htaccess files for this.</li> <li>Are there serious disadvantages to either of these approaches? </li> <li>Is there a "best practice" for this sort of thing, or is it something that each developer tends to decide for themselves? I know WordPress uses option two (though it was more trouble than it was worth when I investigated exactly how they did it).</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload