A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: [RESOLVED] URL rewriting does not work on localhost

  1. #21
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    To remove the index.php part, yes. That's the only way.

  2. #22
    Member
    Join Date
    Jan 2007
    Posts
    79
    Gotcha! I will keep this in mind. Thank you.

  3. #23
    Member
    Join Date
    Jan 2007
    Posts
    79
    Hi Bud,
    Thanks for all the solutions so far, once again. While experimenting with the code in .htaccess file, I stumbled across a new issue. I wanted to basically show pages ending in .php to be rewrited instead of our custom .html files. As such, I modified my .htaccess file to include the following line:

    PHP Code:
    RewriteRule ^([0-9a-zA-Z_-]+)\.php$ /my_domain/index.php?page_slug=$[L
    It gives me the following error:
    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    My Apache Error log says:
    Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

    Do you have any idea of how I can rewrite .php files to our page slugs instead of using .html files?

    Thank you.

  4. #24
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    It's causing a loop for one, because you're redirecting to a *.php page. So it enters a loop. What you need to do is add a check to make sure you're requesting a file that doesn't exist.

    Also, you can't just use a '.'. '.' means something in regular expressions, so you need to escape it.

    Try this out:
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9a-zA-Z_-]+)\.php$ /my_domain/index.php?page_slug=$1 [L]

  5. #25
    Member
    Join Date
    Jan 2007
    Posts
    79
    Brilliant! That works fantastic! Thank you. Is there anything you do not know?

    About the logic: Just wondering why we want it to look up a file that does not exist and how does the new code achieve it? Also I failed to understand what the first 2 lines of the code do in this case

  6. #26
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d


    Those are like if statements. It's basically saying: "if the requested filename is not an existing file (!-f) or a directory (!-d), then use the following RewriteRule.

    You want that because in your case, you're rewriting a request to say, about.php and rewriting that as index.php?page_slug=about. Well, when you hit that request, it also matched on index.php, causing it to rewrite again as index.php?page_slug=index and so on for your endless loop.

    But the catch here is that index.php is an actual file sitting on your server. So the first condition will catch that, and ignore the rewrite.

  7. #27
    Member
    Join Date
    Jan 2007
    Posts
    79
    Ahh.. I see.. Thanks much for explaining.

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center