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!
Related
I currently use version 5.1 of Wordpress, followed by busiprof theme, I do not have any other installed nor do I have a plugin installed.
The problem is that every time I go to Settings> Permanent Links>Post Name> Save Changes, then I try to publish a post and it does not leave me, nor update it. But above the field of categories and labels when creating a theme or update it disappear.
I have the rewrite module activated, and of course, every time I follow the aforementioned route, it creates a .htaccess with the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# 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
I don't see the problem.
I don't know why there are two sets of identical rules in the .htaccess file. Try deleting the top set or rewrite rules just leave this one:
# 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
If that doesn't work just delete the .htaccess file all together and re-save permalinks.
I have some problems with custom Wordpress htaccess file. I want to get simple redirection from all URLs containing numbers after domain, ex:
http://example.com/123 -> to http://example.com
And, my second problem is almost the same, but for 1 specific 4-letter URL, ex:
http://example.com/4554 -> to http://example.com/
but http://example.com/4555 (other 4-letter nubmer should fail)
I've already tried many things, for example:
RewriteRule ^[0-9]{3}$ http://example.com [R=301,L]
But it doesnt work.
Usual Wordpress htaccess file:
# 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
Many thanks for help.
You can use:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(\d{3}|4554)/?$ / [R=301,L]
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>
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
I want to change url structure of page in wordpress
from:http://example.com/page-name/?id=rd123
to:http://example.com/page-name/rd123/
I have tried below code in .htaccess, I am getting ID if i use id numeric(123), but I am getting 404 page not found error if use id alphanumeric(rd123).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page-name/([a-zA-Z0-9-]+)/?$ pagename.php?id=$1 [L]
</IfModule>
what i am missing in above code, it is in wordpress and i am not getting any perfect solution. here, page-name is template.
In this case, use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page-name/([a-zA-Z0-9-]+)/?$ page-name/index.php?id=$1 [L]
</IfModule>
It's not a problem with alphanumeric...
Try This,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^page-name/(.*)/?$ page-name/index.php?id=$1 [L,QSA,NC]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
# END WordPress