I have an issue where I'm using Wordpress + W3 Total Cache + .htaccess + mod_rewrite.
Every querystring variable appended to a URL is causing Wordpress + Total Cache to re-cache a unique file for the request. I know of this Question that was asked but when using it, I feel like I'm not modifying my .htaccess file correctly - Redirection / htaccess rule to kill off query strings to use wordpress super cache
What is the correct way to modify the .htaccess file below to support ignoring all querystring variables but letting them be read by javascript on the page:
# 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>
Before all of your existing rules, but after any rules that you have redirecting (has an R flag), try this:
RewriteCond %{THE_REQUEST} \ /[^\ \?]*\?[^\ ]+
RewriteRule ^ %{REQUEST_URI}? [L]
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /teamin/index.php/$1 [QSA,PT,L]
</IfModule>
ErrorDocument 404 /404.html
This is i use in apache 2.4 ,you can try it !
Related
I have setup a website with recipes but in the process of migration OLD urls to NEW urls I'm facing issues with.
https://example.com/recipes/cheesy-baked-tacos/
This is my old URL structure and In a wordpress site I need to extract last part of the URL "cheesy-baked-tacos" and handle that in the template I use for recipes page.
Now when i click on the URL it goes to 404 page even though recipes page has setup.
I tried following htaccess rules but have no success
RewriteBase /
RewriteRule ^recipes/(.*)$ index.php?l=$1
Thanks in Advance.
Full htaccess file looks like this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^recipes/(.*)$ index.php?l=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
you should check your permalink change to starts with id to without query string
dont change htacces file
you just change permalink in new server
https://example.com/recipes/cheesy-baked-tacos/
this is your old url and has permalink set without query string
new url https://example.com/recipes/cheesy-baked-tacos/id=50 just like
thats why your code have error
Managed to fix the issue with 301 Redirect. Here's what i used if it helps someone.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^recipes/(.*)$ recipe/?post_name=$1 [L,R=301,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I am trying to rewrite some urls by using the .htaccess file in a WordPress environment. I have a WordPress page called "offerta" with two parameters, one of them is a custom ID that I use to generate content.
so, an example url is: http://www.riccionelastminute.it/rlm/offerta/?id=15&titolo=my-title
and I would like it to be: http://www.riccionelastminute.it/rlm/offerta/my-title-15/
this is my .htaccess right now:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rlm/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /rlm/index.php [L]
</IfModule>
# END WordPress
After some research, I tried to add this rule right after the last Rewrite Rule, but it redirects to a 404 page:
RewriteRule ^offerta/([A-Za-z0-9-]+)-([0-9]+)/$ offerta/?id=$2&titolo=$1
I'm not used to play around .htaccess and I'm not an expert.
Am I missing something?
The problem is that the last RewriteRule has the L flag which means that no other rules are applied after it. What you need to do is add your rule before the last one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rlm/
RewriteRule ^index\.php$ - [L]
RewriteRule ^offerta/([A-Za-z0-9-]+)-([0-9]+)/$ offerta/?id=$2&titolo=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /rlm/index.php [L]
</IfModule>
For my current project I have to Redirect 301 some links but when you enter them with some extra get parameters that parameters need to be suffixed on the new url.
Example:
Old:
/language/nl/article-1/?test=123
new:
/language/nl/fa1-artcile-1/?test=123
So I use the following code: (which works fine on my dev env)
RewriteEngine On
Options +FollowSymLinks
RewriteBase /language/nl
RewriteRule /artcile-1/* /language/nl/fa1-artcile-1/$1 [R=301,L]
But once on my production env it does not work, it still redirects to new url but, the get parameters are not appended on the new url.
Edit: It does redirect but it does not append the parameters.
Edit 2: full fill
# 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
The rewrite rule(s) come before the wordpress part and I have about 30 of them.
Any suggestions?
Have it like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^language/nl/article-1/?$ /language/nl/fa1-artcile-1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You need to append the query string:
# 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,QSA]
</IfModule>
# END WordPress
Probably the other answers here are correct as well. But for my case they won't work.
The env it is running up is a MS Azure env, so I need to have a web.config file instead of a .htaccess file (how ever, it works for some part).
Thanks for all the quick help and thinking!
I'm using wordpress for a site and I added an extra php page that uses a query string.
The url I currently have is site.com/page/?query=stuff
and I would like it to be site.com/page/stuff
I understand how to handle a .htaccess ReWrite rule for normal php projects but I'm having a hard time working around wordpresses .htaccess rules which are:
# 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
Thanks in advance for the help.
So in any Wordpress install I've used it automatically identifies /search/query+terms the same as ?s=query+terms, so you really just need to redirect users to the more SEO version, in which case you just need to do the following:
Add the following just below RewriteBase /:
RewriteCond %{QUERY_STRING} s=(.*)
RewriteRule ^$ /search/%1? [L,R=301]
So your final file will look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} s=(.*)
RewriteRule ^$ /search/%1? [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Hope this helps! If your Wordpress install doesn't identify /search/query+terms as a search then let me know and I'll see if I can help you further! You can test this by manually going to the url before you try this, for example: example.com/search/hello+world
We’re using wordpress, and we have the following in the .htaccess:
# 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
We have a URL like http://subdomain.example.com/select-a-card/?q=fuel, and we want to rewrite it so that it becomes something like http://subdomain.example.com/fuel-card/
What do I need to add to the htaccess to do this? Also, will this affect the queries from running that uses GET variables?
nothing, just read the wordpress manual and edit your settings. checkout http://codex.wordpress.org/Using_Permalinks
--- EDIT
This can be done, but only if you have some sort of a standard markup of the url's you want to have rewritten. Ie. if you only want to rewrite the select-a-card url's, or only the url's with a syntax like http://site.com/uri/?q=something. But you if the syntax of the url's differ too much you will have to add a lot of rewrites.
In this specific case something like this should work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# add your specifics below:
RewriteRule ^/select-a-card/\?q=(.*) $1-card/
RewriteRule . /index.php [L]
</IfModule>