2

I have tried all day to get my own rewrite to work in wordpress, but I simply can't get anything to work. I've tried so many different ways but thing is nothing updates in the .htaccess file so I am not sure what I'm doing wrong at this point. This for example I found at the wordpress manual I've tried, but it doesn't work. https://codex.wordpress.org/Rewrite_API/add_rewrite_rule. I heard that you need to flush the rewrite, so I tried adding flush_rewrite_rules(); to the functions.php file too, but it doesn't do any difference. Also I update the wordpress permalinks to get a refresh that way too. But it still doesn't happen anything in the .htaccess file. So what do I do? By the way, I'm using a web hotel server host service so I can't change any "deep" server settings by myself really.

I am using the WP Fastest Cache plugin, which shows a lot in the .htaccess file. I started thinking if that would interfere, but I think not. Have no idea what to do, I really want to make my links work, where I have custom templates with $_GET[''] parameters to nice looking urls. Thing is I only need it to work to start going, as it is now, nothing happens whatever I do. simplest add_rewrite_rule doesn't affect anything. I am sure the .htaccess is in the site root folder, and that I am editing the correct functions.php file.

function custom_rewrite_basic() {
  add_rewrite_rule('^leaf/([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

The .htaccess file (which is completly generated, but with no tracks of my functions rewrite).

# BEGIN WpFastestCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.mywebsite.com [NC]
RewriteRule ^(.*)$ http\:\/\/mywebsite\.com\/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} !(facebookexternalhit)
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !(\/){2}$
RewriteCond %{QUERY_STRING} !.+
RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or]
RewriteCond /storage/content/64/117764/mywebsite.com/public_html/wp-content/cache/all/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L]
</IfModule>
<FilesMatch "\.(html|htm)$">
AddDefaultCharset UTF-8
<ifModule mod_headers.c>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT"
</ifModule>
</FilesMatch>
# END WpFastestCache
# BEGIN GzipWpFastestCache
<IfModule mod_deflate.c>
AddType x-font/woff .woff
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
</IfModule>
# END GzipWpFastestCache
# BEGIN LBCWpFastestCache
<FilesMatch "\.(?i:ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$">
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/svg+xml A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
</IfModule>
<IfModule mod_headers.c>
Header set Expires "max-age=2592000, public"
Header unset ETag
Header set Connection keep-alive
FileETag None
</IfModule>
</FilesMatch>
# END LBCWpFastestCache

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN mywebsite
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

#ENDjapgoi
  • 2
    wordpress internal rewrite rules do not end up in .htaccess, they end up in the global $wp_rewrite array to be processed by wordpress. .htaccess is for external rewrite rules processed by your server. use wordpress.org/plugins/monkeyman-rewrite-analyzer for checking instead. – majick Jun 3 '16 at 1:39
  • 1
    The rules are saved in the database and not needed to be added to the .htaccess file. I would say to deactivate all your plugins and/or switch theme then try to see if it works.. Also try the pagename instead index.php?pagename=$matches[1] e.g sample-page – Samuel Elh Jun 3 '16 at 1:42
3

As someone else suggested, I reactivated my theme and it started working!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.