admin管理员组文章数量:1130349
I'm building a dynamically populated profile page for my site users. This currently uses the following URL structure:
/?&uid=XX
I'd like to improve the look of the URL by inserting the user's nicename to create this URL structure:
/{nicename}/?uid=XX
I know I should be able to do this using a fairly simply rewrite rule in .htaccess, but haven't been able to get the right rule setup.
How can I get this structure / rewrite setup?
I'm building a dynamically populated profile page for my site users. This currently uses the following URL structure:
https://example/members-list-profile/?&uid=XX
I'd like to improve the look of the URL by inserting the user's nicename to create this URL structure:
https://example/members-list-profile/{nicename}/?uid=XX
I know I should be able to do this using a fairly simply rewrite rule in .htaccess, but haven't been able to get the right rule setup.
How can I get this structure / rewrite setup?
Share Improve this question edited Dec 19, 2018 at 0:35 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Dec 18, 2018 at 20:20 Phill HealeyPhill Healey 3781 gold badge7 silver badges20 bronze badges 5 |1 Answer
Reset to default 0It's the redirect in htaccess that will route the "pretty" url into the real querystring based url that is the issue.
So, it would seem you need to "remove" the /{nicename} portion from the "pretty" URL of the form https://example/members-list-profile/{nicename}/?uid=XX.
Try something like the following at the top of your .htaccess file (before the WordPress front-controller) using mod_rewrite:
RewriteRule ^(members-list-profile/)[^/]+/$ $1 [L]
However, unless this maps to a physical file (in which case you should rewrite directly to that file, rather than let mod_dir issue a subrequest) then this might not work with WordPress, since WP still routes the URL based on physical/visible URL - it doesn't necessarily see the rewritten URL. You could issue an external redirect to get around this, but that really defeats the point of having {nicename} in the URL to begin with.
Something like this should probably be done entirely within WordPress, not .htaccess.
I'm building a dynamically populated profile page for my site users. This currently uses the following URL structure:
/?&uid=XX
I'd like to improve the look of the URL by inserting the user's nicename to create this URL structure:
/{nicename}/?uid=XX
I know I should be able to do this using a fairly simply rewrite rule in .htaccess, but haven't been able to get the right rule setup.
How can I get this structure / rewrite setup?
I'm building a dynamically populated profile page for my site users. This currently uses the following URL structure:
https://example/members-list-profile/?&uid=XX
I'd like to improve the look of the URL by inserting the user's nicename to create this URL structure:
https://example/members-list-profile/{nicename}/?uid=XX
I know I should be able to do this using a fairly simply rewrite rule in .htaccess, but haven't been able to get the right rule setup.
How can I get this structure / rewrite setup?
Share Improve this question edited Dec 19, 2018 at 0:35 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Dec 18, 2018 at 20:20 Phill HealeyPhill Healey 3781 gold badge7 silver badges20 bronze badges 5-
1
What have you tried? Presumably you have already changed the URLs in WordPress (in your internal links) and you need to "remove" (not "insert") the
{nicename}part of the URL? – MrWhite Commented Dec 18, 2018 at 22:46 - Any reasoning for the downvote, downvoter? You're entitled to your opinion but it helps no-one if you don't clarify the perceived problem. – Phill Healey Commented Dec 19, 2018 at 11:56
- @MrWhite The building the link is not an issue. It's the redirect in htaccess that will route the "pretty" url into the real querystring based url that is the issue. – Phill Healey Commented Dec 19, 2018 at 11:58
- It wasn't me who downvoted. (I agree, downvotes without comments are not particularly helpful.) I guess the downvote might be because you've not shown what you have tried? But anyway... – MrWhite Commented Dec 19, 2018 at 12:01
- @MrWhite I didn't think it was you, sorry if it came across as if I did. As for the reasoning, it doesn't matter. Donwvoted without a comment helps no-one. I may have a low score on this exchange but I know my way around SO. Downvoting without any comment is just a bit arrogant IMHO. – Phill Healey Commented Dec 19, 2018 at 12:33
1 Answer
Reset to default 0It's the redirect in htaccess that will route the "pretty" url into the real querystring based url that is the issue.
So, it would seem you need to "remove" the /{nicename} portion from the "pretty" URL of the form https://example/members-list-profile/{nicename}/?uid=XX.
Try something like the following at the top of your .htaccess file (before the WordPress front-controller) using mod_rewrite:
RewriteRule ^(members-list-profile/)[^/]+/$ $1 [L]
However, unless this maps to a physical file (in which case you should rewrite directly to that file, rather than let mod_dir issue a subrequest) then this might not work with WordPress, since WP still routes the URL based on physical/visible URL - it doesn't necessarily see the rewritten URL. You could issue an external redirect to get around this, but that really defeats the point of having {nicename} in the URL to begin with.
Something like this should probably be done entirely within WordPress, not .htaccess.
本文标签: url rewritingPretty URL via Rewrite
版权声明:本文标题:url rewriting - Pretty URL via Rewrite 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749084833a2313607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


{nicename}part of the URL? – MrWhite Commented Dec 18, 2018 at 22:46