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
6 votes

remove "index.php" from permalinks

Had exactly same issue. But in my case mod_rewrite was not installed at all for apache. I just installed it with sudo a2enmod rewrite and then changed my Permalink Settings. Worked like a charm. ...
pratpor's user avatar
  • 161
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....
WowPress.host's user avatar
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,699
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,871
2 votes
Accepted

disable Wordpress 404 for one specific page/folder to receive actual php errors

You can add a RewriteRule to your .htaccess to instruct mod_rewrite to stop processing any URI that begins with Staff/ or resolves to Staff: # BEGIN WordPress <IfModule mod_rewrite.c> ...
bosco's user avatar
  • 6,745
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,871
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,231
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,871
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,871
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,488
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,871
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,871
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,871
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

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

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,871
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
  • 415
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,871
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,871
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,871
1 vote
Accepted

Rewrite rule and display of post

I don't understand why but the regex seemed to be the last issue. It was catching it but even with the post name hardcoded in it didn't work correctly. This is the final working version. add_filter(...
garrettlynchirl's user avatar
1 vote

force www rewrite if wordpress put in a folder

Place this above the # BEGIN WordPress line. RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]
WebElaine's user avatar
  • 9,310
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.2k
1 vote

Rewrite Rules Are Redirecting and Not Passing VARs

I faced similar issue multiple times and in my case, the redirect was caused by redirect_canonical() function placed in wp-includes/canonical.php. This function tries to redirect to base (canonical) ...
Ján Janočko's user avatar

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