admin管理员组文章数量:1313001
I'm looking to use .htaccess
to rewrite admin page URLs. I'd like to change it from:
.php?page=whatever&id=5&var=10
to
;var=10
Right now I have:
RewriteEngine On
RewriteRule ^members$ admin.php?page=members& [L,E=CLEAN_CONTACT_URL:1,QSA]
RewriteRule ^add-members$ admin.php?page=add-members [L,E=CLEAN_CONTACT_URL:1,QSA]
RewriteRule ^delete$ admin.php?page=delete& [L,E=CLEAN_CONTACT_URL:1,QSA]
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteCond %{ENV:REDIRECT_CLEAN_CONTACT_URL} !1
RewriteRule ^admin.php$ /wp-admin/%1?%2 [R,L]
Which changes it to:
;id=5&var=10
I don't mind adding each 'section' (e.g. members / add-member / delete) to my .htaccess
. Although, if there is a better way, I'd be happy to see it!
I'm using internal and external redirections, so that when you click on a admin URL and it goes to wp-admin/admin.php?page=somewhere
, it rewrites the URL for the browser, and then finds the rewritten URL. I would like to use 'pretty' admin links. Example:
Is easy to remember and intuitive. Eventually, I will rename /wp-admin
to /user
as well.
I'm looking to use .htaccess
to rewrite admin page URLs. I'd like to change it from:
http://example/wp-admin/admin.php?page=whatever&id=5&var=10
to
http://example/wp-admin/whatever?id=5&var=10
Right now I have:
RewriteEngine On
RewriteRule ^members$ admin.php?page=members& [L,E=CLEAN_CONTACT_URL:1,QSA]
RewriteRule ^add-members$ admin.php?page=add-members [L,E=CLEAN_CONTACT_URL:1,QSA]
RewriteRule ^delete$ admin.php?page=delete& [L,E=CLEAN_CONTACT_URL:1,QSA]
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteCond %{ENV:REDIRECT_CLEAN_CONTACT_URL} !1
RewriteRule ^admin.php$ /wp-admin/%1?%2 [R,L]
Which changes it to:
http://example/wp-admin/whatever&id=5&var=10
I don't mind adding each 'section' (e.g. members / add-member / delete) to my .htaccess
. Although, if there is a better way, I'd be happy to see it!
I'm using internal and external redirections, so that when you click on a admin URL and it goes to wp-admin/admin.php?page=somewhere
, it rewrites the URL for the browser, and then finds the rewritten URL. I would like to use 'pretty' admin links. Example:
http://example/wp-admin/members
Is easy to remember and intuitive. Eventually, I will rename /wp-admin
to /user
as well.
2 Answers
Reset to default 1You can try this (sorry, not previously tested). See comments inline for explanation:
RewriteEngine On
## if any string separated by | is matched, it will append to ?page=
RewriteRule ^(members|add-members|delete)$ admin.php?page=%1 [L,E=CLEAN_CONTACT_URL:1,QSA]
## If querystring starts with page= and is followed by any string separated by |
## put that in the first group. Then put any other characters in second group
RewriteCond %{QUERY_STRING} ^page=(members|add-members|delete)(.*)$
RewriteCond %{ENV:REDIRECT_CLEAN_CONTACT_URL} !1
RewriteRule ^admin.php$ /wp-admin/%1?%2 [R,L]
You can probably rewrite the rule to be more generic. The main issue you're having with:
RewriteCond %{QUERY_STRING} ^page=(.*)$
is that the (.*)$
matches ALL characters including your subsequent &foo=bar
so the entire querystring is lumped into %1
and your %2
is empty.
Not really sure on what you want your end goal to look like, but from I understand, here's my approach. In your .htaccess
add the following rule in between the <IfModule mod_rewrite.c>
tag:
RewriteCond %{QUERY_STRING} (^|&)page=(.*)
RewriteRule ^wp-admin/admin.php(.*)$ wp-admin [R=301,L]]
Based off of the default .htaccess
generated by WordPress, it should now look like the following with your custom RewriteRule
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Custom Rules
RewriteCond %{QUERY_STRING} (^|&)page=(.*)
RewriteRule ^wp-admin/admin.php(.*)$ wp-admin [R=301,L]
</IfModule>
This will then redirect pages such as:
http://example/wp-admin/admin.php?page=whatever&id=5&var=10
to
http://example/wp-admin?page=whatever&id=5&var=10
If you could clarify your question specifically on what you want your expected results to be based on some example URLs, I could give you a more concrete answer.
本文标签: url rewritingHow to remove quotadminphppagequot from wpadmin using htaccess
版权声明:本文标题:url rewriting - How to remove "admin.php?page=" from wp-admin using .htaccess? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741886660a2403061.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论