Note that there are some explanatory texts on larger screens.

plurals
  1. POApache Mod-Rewrite Question
    primarykey
    data
    text
    <p>I have a PHP scripted named index.php inside a folder named blog. There are three different views.</p> <ol> <li><a href="http://www.myDomain.com/blog/index.php" rel="nofollow noreferrer">http://www.myDomain.com/blog/index.php</a></li> <li><a href="http://www.myDomain.com/blog/index.php?tags=list" rel="nofollow noreferrer">http://www.myDomain.com/blog/index.php?tags=list</a> of categories</li> <li><a href="http://www.myDomain.com/blog/index.php?post=name" rel="nofollow noreferrer">http://www.myDomain.com/blog/index.php?post=name</a> of post</li> </ol> <p>I would like to change the view based on the URL.</p> <ol> <li>/blog redirects to number 1 above</li> <li>/blog/name-of-category redirects to numbe 2 above</li> <li>/blog/name-of-category/name-of-post redirects to number 3 above.</li> </ol> <p>Right now I have the following mod_rewrite rules.</p> <pre><code>RewriteRule ^blog$ blog/index.php [L] RewriteRule ^blog/(.+)/(.+)$ blog/index.php?post=$2 [L] RewriteRule ^blog/(.+)$ blog/index.php?tags=$1 [L] </code></pre> <p>This does not work, and I'm not sure why. Right now it always redirects to the last URL:</p> <p><code>blog/index.php?tags=$1</code></p> <p>And the GET data contains "index.php."</p> <p>Also, if add a forward slash to the final rule like so:</p> <pre><code>RewriteRule ^blog/(.+)/$ blog/index.php?tags=$1 [L] </code></pre> <p>All redirects work fine. The problem is, I'm <strong>required</strong> to have a forward slash at the end of the URL if I want the category view.</p> <p>Any ideas what's happening here? how I can fix this?</p> <hr> <p>Thanks for the replies. I figured out that my problem was a side effect of having my scripts inside the folder named "blog". Here's what index.php looked like:</p> <pre><code>&lt;?php define ('BASE_PATH', "../blog/"); include_once(BASE_PATH . 'controller/Controller.php'); $controller = new Controller(); $controller-&gt;invoke(); </code></pre> <p>See the problem? Because my script's base path was "blog", mod_rewrite was rewriting all my references inside the program. By renaming my script folder to blogScript, it fixed the problem.</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.
    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