Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I create friendly URLs with .htaccess?
    primarykey
    data
    text
    <p>I'm having a hard time with .htaccess. I want to create friendly URLs for a site I'm working on...</p> <p>Basically I want to convert this:</p> <pre><code>http://website.com/index.php?ctrl=pelicula&amp;id=0221889 http://website.com/index.php?ctrl=pelicula&amp;id=0160399&amp;tab=posters </code></pre> <p>Into this:</p> <pre><code>http://website.com/pelicula/0221889/ http://website.com/pelicula/0221889/posters/ </code></pre> <p>In case I need it later I would also want to know how to add the article title to the end of the URL like this (I'm using PHP):</p> <pre><code>http://website.com/pelicula/0221889/the-article-name/ http://website.com/pelicula/0221889/the-article-name/posters/ </code></pre> <p>Note: Stackoverflow method is also good for me, for example the url of this question is:</p> <pre><code>http://stackoverflow.com/questions/3033407/htacces-to-create-friendly-urls-help-needed </code></pre> <p>But you can put anything after the id and it will also work. like this:</p> <pre><code>http://stackoverflow.com/questions/3033407/just-anything-i-want </code></pre> <p>I have used some automatic web tools for creating the .htacces file, but its not working correctly. So I ask for your help.</p> <p>I will also be glad if you can recommend .htacces best practices and recommendations..</p> <p><strong>EDIT: based on some answers I get here I put this:</strong></p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/([^/]+)/([^/]+)/?([^/]*)/?$ index.php?ctrl=$1&amp;id=$2&amp;tab=$3 [QSA,L] &lt;/IfModule&gt; </code></pre> <p>But I get the default host 'page not found' error.</p> <p>I also tried:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/(\d+)/([^/]+)/?$ index.php?ctrl=$1&amp;id=$2&amp;tab=$3 [QSA,L] RewriteRule ^([^/]+)/(\d+)/?$ index.php?ctrl=$1&amp;id=$2 [QSA,L] RewriteRule ^([^/]+)/?$ index.php?ctrl=$1 [QSA,L] &lt;/IfModule&gt; </code></pre> <p>This also does not work. It takes me to my default 404.php page.</p> <p>mod_rewrite is enabled and working.</p> <p>Help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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