SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add two rewrite conditions to htaccess file

    I have a .htaccess file on root.On root folder there are three files.

    index.php
    article.php
    event.php
    on index.php there two href to event and news.php files.

    to article.php:
    PHP Code:
    $articleId=123;
    $articleTitle='First Article';
    echo 
    '<a href="'.$articleId.'&'.str_replace(" ","-",$articleTitle).'">Read More</a>'
    and to event.php:
    PHP Code:
    $eventId=789;
    $eventTitle='First Event';
    echo 
    '<a href="'.$eventId.'&'.str_replace(" ","-",$eventTitle).'">Read More</a>'
    Above two href's are on the index.php.

    To handle the redirect i have written following code on htaccess file.
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) article.php?arid=$1&$2
    RewriteRule (.*) event.php?eveid=$1&$2
    These are the types on urls that we need to see on browser.
    Code:
    article:localhost/system/articleid-articletitle and then for event : localhost/system/eventid-eventtitle
    But when i add the second rewrite line,system is not loading and when i remove one rewrite condition system works fine. can anyone help me out?.

    Thanks in advance and hope i have clearly mention the question.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ishakya View Post
    echo '<a href="'.$articleId.'&'.str_replace(" ","-",$articleTitle).'">Read More</a>';[/PHP]
    ...
    echo '<a href="'.$eventId.'&'.str_replace(" ","-",$eventTitle).'">Read More</a>';[/PHP]
    ...
    article:localhost/system/articleid-articletitle and then for event : localhost/system/eventid-eventtitle
    How exactly are you supposed to distinguish between an article URL and an event URL? If you had a URL such as /123-sometitle is there any way to know if it's an article or an event?

    Quote Originally Posted by ishakya View Post
    But when i add the second rewrite line,system is not loading and when i remove one rewrite condition system works fine. can anyone help me out?.
    The first rewrite will match every non-file request and send it to article.php. The second rewrite will match every request, even if it's for a real file, even if it's for article.php itself, and send it to event.php.

    We can certainly help, but we'll first need to know the answer to the question above to distinguish between the two kinds of URLs.
    "First make it work. Then make it better."


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •