Note that there are some explanatory texts on larger screens.

plurals
  1. POhtaccess conditional rewrite
    primarykey
    data
    text
    <p>I am fiddling around with .htaccess and mod_rewrite. I have a site that has two types of URLs which I want to rewrite:</p> <ul> <li><code>/index.php?nav=$2</code> </li> <li><code>/index.php?nav=41&amp;intNewsId=$3</code> -- 41 is static, the news nav is always 41</li> </ul> <p>I want to rewrite them to:</p> <ul> <li><code>/pagename/id</code></li> <li><code>/news/pagename/id</code></li> </ul> <p>I already made a piece of code that works, BUT if I add the last line the second line stops working, and <strong>I can imagine thats because the conditions in the third block are also true for the second block</strong>. But I cant figure out how to use conditions right. (Both blocks work individual)</p> <pre><code>Options +FollowSymlinks RewriteEngine on # Reroute rules that end on / RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$ /$1/$2/ [R] # Make the system understand pagename/96 RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/$ /index.php?nav=$2 # Make the system understand news/pagename/99 RewriteRule ^(.*)\/(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/$ /index.php?nav=41&amp;intNewsId=$3 </code></pre> <p>I tried everything I could think of, but I'm not too familiar with this regex style of typing or conditional blocks in htaccess.</p> <p>Solution: I fixed my own code, I just stripped the second $ so the condition didnt interfere with the last one</p> <pre><code>Options +FollowSymlinks RewriteEngine on # Reroute rules that end on / RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$ /$1/$2/ [R] # Make the system understand pagename/96 RewriteRule ^(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/ /index.php?nav=$2 # Make the system understand news/pagename/99 RewriteRule ^(.*)\/(.*)\/([0-9]|[1-9][0-9]|[1-9][0-9][0-9])/$ /index.php?nav=41&amp;intNewsId=$3 </code></pre> <p>Thanks for the answers all!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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