Skip to main content
11 votes

How can I create custom URL routes?

Another way to do it: add_action('init', function() { add_rewrite_rule( '^properties/([0-9]+)/?', 'index.php?pagename=properties&property_id=$matches[1]', ...
Christian Lescuyer's user avatar
3 votes
Accepted

Rewrite rule to load images from production does nothing

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] # If images not found on development site, load from production RewriteCond %{REQUEST_URI} ^/wp-...
MrWhite's user avatar
  • 3,881
3 votes

Hosting a Wordpress blog as a sub folder from a S3 website

You are using Cloudfront in front of S3, so in order to mix in 2 sources of content you need to on your blog.mycompany.com - add rewrites of blog/* -> /* so that your blog can handle blog.mycompany....
maxicusc's user avatar
  • 125
3 votes

Remove base slug in permalinks of hierarchical custom post type

This will allow you to use the post name without the slug. Essentially anytime the link is requested it can be altered to exclude the base post type. And any time a query runs with just a name, the ...
jgraup's user avatar
  • 9,834
2 votes
Accepted

Mod_rewrite delete parameter in 301 Redirect

I want to remove all instances on aff=x regardless of how many other parameters in the URL. Assuming you want to keep any other URL parameters (in any order) and simply remove the aff=number ...
MrWhite's user avatar
  • 3,881
2 votes

mod_rewrite empties QUERY_STRING if starting with number

Thanks to Tom, I looked more carefully to the plugins. And I can confirm that the problem is NOT RELATED to mod_rewrite, but to a plugin conflict. (sorry that I posted such a suspicion, but I read ...
nounours's user avatar
2 votes

.htaccess rewriterule being ignored - tyring to remove dates from WP posts

You can actually change them in Settings -> Permalinks and it will change the link that generated for the post. And if you still be unhappy with result you can remove WordPress rewrite rules for dates ...
Oleg Butuzov's user avatar
  • 3,214
2 votes
Accepted

Remove File Extension for Page Outside of WordPress

...but that still didn't remove the extension. To be clear, the extension should already be removed in the HTML anchor/link. The purpose of .htaccess is primarily to rewrite the extensionless URL ...
MrWhite's user avatar
  • 3,881
2 votes
Accepted

Without index.php in permalinks I get 404 across site

Adding junk doesn't do anything either. That suggests your .htaccess file is not being processed at all. You need to set AllowOverride All in the appropriate <Directory> container in the main ...
MrWhite's user avatar
  • 3,881
2 votes
Accepted

Wordpress rewrite rules don't need ^?

I just did a test and it seems like the rewrite rules imply ^ if you do not specify it. In my test I found: rule 'foo' matched url 'foo' rule '^foo' matched url 'foo' rule 'foo' did not match url '...
mozboz's user avatar
  • 2,608
2 votes
Accepted

blocking access to all post/tag URIs via htaccess

RewriteCond %{REQUEST_URI} ^post/tag/ RewriteRule .* - [F] The REQUEST_URI server var does start with a slash (it is a full root-relative URL-path), although you do say you have tried this "with ...
MrWhite's user avatar
  • 3,881
2 votes
Accepted

Protect Upload Folder Files With Ampersand Problem

As you've stated, the B flag is required in this case. But this should be [B,L], not [BNC] as you've quoted a couple of times? Not sure where you got [BNC] from, but that's wholly invalid and would ...
MrWhite's user avatar
  • 3,881
2 votes
Accepted

.htaccess redirects disappeared after re-saving permalinks

To reduce multiple slashes at the start of the URL-path (or in fact anywhere in the URL-path) to a single slash (there is always at least 1 slash at the start of the URL-path, even if you can't see ...
MrWhite's user avatar
  • 3,881
2 votes

flush_rewrite_rules() not working with update_option_{$option}

flush_rewrite_rules() should be called very early within the Wordpress initialization. The reason is that the entpoints cannot be changed afterwards. A solution could look like this: function ...
Thomas Zwirner's user avatar
1 vote
Accepted

404 not working, going to homepage; how to fix?

In my case, the issue was the multi-site config attribute NOBLOGREDIRECT This had been set in wp-config.php... // Redirect non-existent Multisite subdomain calls to www primary site define( '...
Robert Andrews's user avatar
1 vote
Accepted

Custom rewrite not working

Try to add this one function add_rewrite_rules() { $newrules = array('^testrewrite/([0-9]+)/?'=> 'index.php?page_id=$matches[1]'); return $newrules ; } add_filter('rewrite_rules_array', '...
Tejas Gajjar's user avatar
1 vote

.htaccess rule to redirect old URLs to new structure

Am I missing something simple? You need the L flag (to prevent further processing) and this directive should go at the very top of your existing .htaccess file (ie. before the # BEGIN WordPress ...
MrWhite's user avatar
  • 3,881
1 vote
Accepted

Permalink sub-routing catch-all

You can add an internal rewrite so WordPress recognizes these requests. In the same function hooked to init where you add the post type, you can add: add_rewrite_tag( '%tutorial_fragment%', '([^/]+)' ...
Milo's user avatar
  • 78.8k
1 vote
Accepted

How to write .htaccess so that https is on for subpages only but not the home page

Presumably your .htaccess file is located in the /abc subdirectory? In which case you can do something like the following to force HTTPS on all sub-pages, except the homepage: This needs to go at the ...
MrWhite's user avatar
  • 3,881
1 vote

htaccess rewrite for author query string when WP is in subfolder

This is probably best handled the "WordPress way" as @Iceable suggests, rather than using .htaccess, however, to answer your specific queries... But no matter how I try to edit the second part... ...
MrWhite's user avatar
  • 3,881
1 vote

htaccess rewrite for author query string when WP is in subfolder

I assume you are trying to prevent scanners obtaining your site's user names. And for security I believe in blocking at the first perimeter gate possible i.e. .htaccess not PHP. No idea why subdirs ...
scytale's user avatar
  • 424
1 vote

htaccess rewrite for author query string when WP is in subfolder

The question is about doing this with .htaccess, but why not disabling author pages from within WordPress instead? This would achieve the same result while making the subdirectory concern irrelevant ...
Iceable's user avatar
  • 865
1 vote
Accepted

How To Fix A Redirect Chain

The non-www to www redirect is most certainly being handled (later) by WordPress. Your existing redirect in .htaccess is HTTP to HTTPS only, on the same host - which is actually the preferred (read: ...
MrWhite's user avatar
  • 3,881
1 vote

mod_rewrite empties QUERY_STRING if starting with number

Finally, completely understood and solved the problem using @MrWhite 's advice to use mod_rewrite to rewrite the query. Thanks! To explain: 1) My http://example.com/db/?p=foo is (and this I didn't ...
nounours's user avatar
1 vote

Custom rewrite rule, url returning 404

I think I figured it out... almost. I needed to use WordPress' own rewrite engine to define the rewrite rules so it recognizes what I'm doing. So I added this to my WordPress theme's functions.php: ...
Bryan's user avatar
  • 41
1 vote

Deny access to uploads folder with exceptions

This actually does not work great at all as the existence of the cookie does not indicate that the user is logged in, or even that he was ever logged in. All it indicates is that someone somehow set ...
Mark Kaplun's user avatar
  • 23.7k
1 vote

Remove year and month in URL using .htaccess

Why not change your permalinks to "Post Name" in Settings, Permalinks?
Rick Hellewell's user avatar
1 vote

Wordpress on a subdirectory of Laravel - Wordpress pretty permalinks inner page shows laravel

I accidentally found a solution. I was using a local XAMPP installation and there was no way around it. Though when I uploaded the site to a live server it worked fine. I hope this helps someone in ...
Avi's user avatar
  • 159
1 vote
Accepted

How to create a redirect in the .htaccess file, with 2 exceptions

Try the following, before the existing WordPress directives: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !^(abc|abc-def-g)$ / [R,L] This states that for any ...
MrWhite's user avatar
  • 3,881
1 vote
Accepted

Place static HTML files in path below WordPress page

By creating a physical directory the same as a (virtual) WordPress URL you have created a conflict. The URL needs to be routed through WP, but the default front-controller (the .htaccess code shown ...
MrWhite's user avatar
  • 3,881

Only top scored, non community-wiki answers of a minimum length are eligible