admin管理员组

文章数量:1313318

My .htaccess files are intercepting WordPress' .htaccess file.

Which modules and which settings (specified by .htaccess) are required for WordPress to work? In other words, where can I find WordPress' default .htaccess file?

My .htaccess files are intercepting WordPress' .htaccess file.

Which modules and which settings (specified by .htaccess) are required for WordPress to work? In other words, where can I find WordPress' default .htaccess file?

Share Improve this question edited Sep 26, 2016 at 18:07 Ethan Rævan 4,0295 gold badges27 silver badges55 bronze badges asked Mar 17, 2012 at 11:10 user14016user14016 1
  • There is the WordPress codex article about htaccess files. – Nicolai Grossherr Commented May 18, 2015 at 11:34
Add a comment  | 

4 Answers 4

Reset to default 36

Here is the default code for that file.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

you can check it here for default htaccess file.

http://codex.wordpress/Using_Permalinks.

Thanks. I hope it helps little.

WordPress does not contain .htaccess in file form.

The rules are written into file by save_mod_rewrite_rules() function and are generated by $wp_rewrite->mod_rewrite_rules().

Note that multisite installation has different (more complex) rules and seems to be handled differently.

Use the latest version of default .htaccess

https://wordpress/support/article/htaccess/.

Use the Freenode's #wordpress to find the appropriate documentation, usually in the /topic. There I found the key Class WP_Rewrite here, the official wordpress is at the best misleading and marketing. Anyway, do not mix Apache's rewrite rules with WP's rewrite rules although the naming of WP is probably from Apache's equivalent.

The WP_Rewrite API states

You can add rules to trigger your page view and processing using this component. The full functionality of a front controller does not exist, meaning you can't define how the template files load based on the rewrite rules.

so you must use the API to do the changes, not fully sure what it means but I think it means you cannot trust in your hard-coded .htaccess -files -- things may change even with different WD -versions! So use the API.

intercepting

The code here has some conditions if the .htaccess -file exists -- not 100% of their inferences because not well-documented and cannot understand the naming there but the central message is probably that the safe way to maintain the rewrite rules is to use the WP_Rewrite API, WP may change in the future.

For example, a simple Apache-rewrite RewriteRule ^hello$ Layouts/hello.html [NC,L] is apparently something like add_rewrite("^hello$", "Layouts/hello.html"), haven't tested but tried to follow the API below:

add_rewrite_rule (line 19)
Add a straight rewrite rule.

see: WP_Rewrite::add_rule() for long description.
since: 2.1.0
void add_rewrite_rule (string $regex, string $redirect, [string $after = 'bottom'])
string $regex: Regular Expression to match request against.
string $redirect: Page to redirect to.
string $after: Optional, default is 'bottom'. Where to add rule, can also be 'top'.

Related

  1. http://codex.wordpress/Rewrite_API/add_rewrite_rule

  2. http://pmg.co/a-mostly-complete-guide-to-the-wordpress-rewrite-api

  3. Thanks to toscho for assisting here, some small-talk in chat.

本文标签: Default htaccess file for WordPress