admin管理员组文章数量:1291127
I wanna add a simple rewrite rule
RewriteRule ^apply\/? [L]
my .htaccess file is like
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If I add my rule to the last line of this file, it won't work. But if I add it into right after
RewriteEngine On
it will work. But it will get overwritten.
I don't understand why this line won't work outside of wordpress block. I am aware of there is a API to add rewrite rule, just wanna know why it won't work for learning purpose.
I wanna add a simple rewrite rule
RewriteRule ^apply\/? https://docs.google/forms/d/e/1FAIpQLSf5IrOhg0E_NAGZnOvMuaXhU80sio8bukaWVBkb87eEOa9kTw/viewform [L]
my .htaccess file is like
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If I add my rule to the last line of this file, it won't work. But if I add it into right after
RewriteEngine On
it will work. But it will get overwritten.
I don't understand why this line won't work outside of wordpress block. I am aware of there is a API to add rewrite rule, just wanna know why it won't work for learning purpose.
Share Improve this question edited Jun 15, 2021 at 15:25 Fabian Mossberg 4043 silver badges12 bronze badges asked Jun 14, 2021 at 23:04 shenkwenshenkwen 1311 silver badge9 bronze badges 1- "it will work. But it will get overwritten." - What do you mean by "overwritten"? You can't internally rewrite a request to an external domain (as you appear to be trying to do). The directive you posted will result in an external 302 redirect. – MrWhite Commented Jun 15, 2021 at 15:27
1 Answer
Reset to default 1As it says in the file:
The directives (lines) between "BEGIN WordPress" and "END WordPress" are dynamically generated, and should only be modified via WordPress filters. Any changes to the directives between these markers will be overwritten.
Put your code before #BEGIN WordPress
or after # END WordPress
.
However, in the [L]
flag means LAST, so no more rules will be run if that one has a hit.
So this rule will need to be above the # BEGIN WordPress
Try this .htaccess
:
# Just to be safe, wrap it in IfModule mod_rewrite.c, so that
# it does not kick in unless mod rewrite is enabled.
<IfModule mod_rewrite.c>
RewriteRule ^apply\/? https://docs.google/forms/d/e/1FAIpQLSf5IrOhg0E_NAGZnOvMuaXhU80sio8bukaWVBkb87eEOa9kTw/viewform [L]
</IfModule>
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
There is a great tool to debug your .htaccess
file, it's called htaccess tester. I prepared two examples:
本文标签: url rewritingAdding rewrite rules directly to htaccess file
版权声明:本文标题:url rewriting - Adding rewrite rules directly to .htaccess file 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741502568a2382131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论