wordpress SEO友好网址是否可以在不使用htaccess的情况下工作?

Wordpress uses friendly seo url without using htaccess.

Can any explain this to me please how they do it.

The only way i can think of is to do something like this.

domain.com/index.php/nnn/mmmm/

But wordpress does not use index.php

I know they are not using htaccess.

Please let me know.

Thank you.

WordPress actually has a single .htaccess file that they don't need to change which redirects all requests to index.php

index.php then looks at the permalinks rules and runs a few database queries to determine which page to send you.

So for instance if the permalink rule is %postdate%/%postname% (may not be the actual WordPress permalink variables. I haven't been using WordPress for too long) then it would just use regular expressions (or combinations of substr() and strpos()) to put %postdate% and %postname% into variables. Next it runs a simple database query for any item matching that date and that name. If nothing is found, redirect to search. If you find more than one, list them all (like a category page). If you find one and only one, send that page.

As far as actually "sending" the page, that's just a matter of settings certain variables (such as $the_post['content']) and then include()'ing the proper theme file.

include()'ing the theme file is a simple if() statement.

if(file_exists("wp-content/themes/<your_theme>/$the_post['type'].php")){
    include("wp-content/themes/<your_theme>/$the_post['type'].php");
} else {
    include("wp-content/themes/<your_theme>/index.php");
}

Mind you these aren't the exact variable names or the exact functions as they occur. This is just a very simplified version to give the general idea of how these systems work.

Wordpress does use .htaccess files. You can modify the permalinks in the permalinks section your wordpress site. You can see information on it here.

If you are using IIS you can use this method

Wordpress does actually use .htaccess. Make sure you have hidden files displayed! If you're FTP-ing, there'll be a setting in your client.

To answer the main question:

No.

As for the other points of yours:

Wordpress uses friendly seo url without using htaccess.

USUALLY it does not.
USUALLY it requires the .htaccess to make nice urls work.
However, as Wordpress' Codex says:

If you are using IIS 7 and have admin rights on your server, you can use Microsoft's URL Rewrite Module instead. Though not completely compatible with mod_rewrite, it does support WordPress's pretty permalinks.

So they are always using some kind of rewrite module anyway.

Can any explain this to me please how they do it.


There is one interesting thing to explain:

  • There is only one .htaccess file.
  • Which would not be so interesting if it would contain some kind of general rule rewriting urls to some.php's GET parameters (domain.com/verynice => domain.com/index.php?page=verynice).
  • But that is not happening.

What is happening is that
It rewrites ANY url that is NOT a specific FILE or DIRECTORY to index.php EXCEPT the index.php (to prevent infinite loop).

So urls like domain.com/blah/blah and domain.com/lol/trololo are both actually requesting the index.php - the only difference is in the requested URI.

Using superglobal variables like $_SERVER['REQUEST_URI'] they get the requested URI and after that they parse the requested URI and store the results in varibles accordingly.

The only way i can think of is to do something like this.

domain.com/index.php/nnn/mmmm/

In common explanation of the URL this is NOT request to the index.php file itself.
It is a request for the "mmmm" folder in folder "nnn" which is in folder "index.php".

However apache usually understand this as a request for the index.php file .

For other files e.g. my.file domain.com/my.file is a file request, domain.com/my.file/ is a folder request (notice the slash / at the end)

But wordpress does not use index.php

That is NOT TRUE.

Especially if you are using nice-urls the index.php is practicaly fundamental for Wordpress.

I know they are not using htaccess.

This point of yours could meant 3 things:

  1. They are using the htaccess but not for processing the URL (which I've explained above)
  2. They are not using it at all - not true, unless they would be using the MS' URL Rewrite Module
  3. You don't know. You did not provide any information about how did you find out they are not using it, so we can't know if you really know or you just think that :)

Please let me know.

I let you know. And I hope I've answered all your questions :), if not - use comments :)

Thank you.

You are welcome.

I was happy to help :) ☺ ☺ ☺ ☺ ☺