Questions about rewriting URLs with. htaccess

Source: Internet
Author: User
I use it. Apache, want to use. htaccess implements the ability to rewrite URLs, but encounters a magical problem that cannot be resolved, first look at my rewrite rule, my. htaccess file:

RewriteEngine onRewriteCond $1 !^(index\.php|public)RewriteRule ^(.*)$ /PFW/index.php?$1 [L]

With this rule, you can forward most of the path access to the index.php page, for example:

http://localhost/test/= Http://localhost/index.php?/test
Http://localhost/example = Http://localhost/index.php?/example

However, the only path that cannot be forwarded to index.php:

http://localhost/index///This path will be accessed directly, and will not be located to index.php

The initial figure is because there is a index.php file under the directory, because when I create test.php in the same directory in index.php:

http://localhost/test///This path will not be forwarded, before it can be forwarded

That is, when the directory has a PHP file with the same name as the path, my. htaccess rewrite rule will not take effect. I wonder if anyone has ever met the same problem as me? Until now have not thought the solution, asks everybody to point the maze t^t

This issue has been closed due to:

Reply content:

I use Apache, I want to use the. htaccess implementation of the function of rewriting the URL, but encountered a very magical problem can not be resolved, first look at my rewrite rules, my. htaccess file:

RewriteEngine onRewriteCond $1 !^(index\.php|public)RewriteRule ^(.*)$ /PFW/index.php?$1 [L]

With this rule, you can forward most of the path access to the index.php page, for example:

http://localhost/test/= Http://localhost/index.php?/test
Http://localhost/example = Http://localhost/index.php?/example

However, the only path that cannot be forwarded to index.php:

http://localhost/index///This path will be accessed directly, and will not be located to index.php

The initial figure is because there is a index.php file under the directory, because when I create test.php in the same directory in index.php:

http://localhost/test///This path will not be forwarded, before it can be forwarded

That is, when the directory has a PHP file with the same name as the path, my. htaccess rewrite rule will not take effect. I wonder if anyone has ever met the same problem as me? Until now have not thought the solution, asks everybody to point the maze t^t

Give it a try.

RewriteEngine On#RewriteBase ...RewriteRule ^(index\.php$|public.*) $1 [QSA,L]RewriteRule ^(.*)$ index.php?$1 [QSA,L]
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.