: URL RewriteRule doesn't work when using WP Database Participants in my WordPress website I'm using WP Participants Database plugin in a site developed using WordPress and I'm trying to transform:
I'm using WP Participants Database plugin in a site developed using WordPress and I'm trying to transform:
example.com/subfol1/subfol2/?listpage=3&search_field=none&value=&operator=LIKE&sortBy=denumire&ascdesc=asc&submit=&sortstring=denumire&orderstring=asc#participants-list
into:
example.com/subfol1/subfol2/3/
My .htaccess is the one below:
SetEnv no-gzip dont-vary
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ [L]
RewriteRule . index.php [L]
RewriteRule ^produse/piese-schimb-utilaje-agricole/([0-9]+)/?$ ^produse/piese-schimb-utilaje-agricole/?listpage=&search_field=none&value=&operator=LIKE&sortBy=denumire&ascdesc=asc&submit=&sortstring=denumire&orderstring=asc#participants-list [NC,L]
My last RewriteRule does not rewrite the ugly URL. Where did I go wrong?
More posts by @Odierno851
2 Comments
Sorted by latest first Latest Oldest Best
As Stephen has already stated, the order of the directives needs to be changed... the "catch-all" rewrite needs to be last.
However, there are few other things to consider...
My last RewriteRule does not rewrite the ugly URL.
The last RewriteRule attempts to internally rewrite the "pretty" URL back to the "ugly" URL. This is required (although there are problems with it - see below). However, there is no code here that rewrites (or rather, redirects) the "ugly" URL as is suggested. Ideally, the "pretty" URL should be generated by your application, not in .htaccess.
RewriteRule ^produse/piese-schimb-utilaje-agricole/([0-9]+)/?$ ^produse/piese-schimb-utilaje-agricole/?listpage=&search_field=none&value=&operator=LIKE&sortBy=denumire&ascdesc=asc&submit=&sortstring=denumire&orderstring=asc#participants-list [NC,L]
You need to remove the ^ prefix from the RewriteRule substitution - this is a string, not a regex. You also need the NE (noescape) flag, otherwise the special chars in the substitution (the # in this case) will be escaped (percent encoded).
is still shown in the ugly form.
As mentioned above, the "pretty" URL should be generated by your application. To catch "ugly" URLs that have been indexed you can externally redirect requests for the "ugly" URL to the "pretty" URL. Note, however, that if you are still linking to the "ugly" URL in your application then this will result in an external redirect everytime a user follows a link on your site - which is not desirable.
Something like the following near the top of your script (before the internal rewrites):
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(subfol1)/(subfol2)/?listpage=(d+)&search_field=none&value=&operator=LIKE&sortBy=denumire&ascdesc=asc&submit=&sortstring=denumire&orderstring=asc
RewriteRule ^ /%1/%2/%3 [R=301,L]
Check against THE_REQUEST in order to avoid a rewrite loop (resulting from the internal rewrite back to the "ugly" URL).
I think the problem is the order of your rewrite rules.
RewriteRule . index.php [L]
needs to be the last rewrite rule. It rewrites all URLs and is marked as last. No rewrite rule that comes after it is going to have a chance of working.
Try moving your produse up near the rewrite rule that adds a trailing slash to the admin page.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.