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>
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.
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
I want to write a own rewrite rule into my htacces. The redirection itself works fine but Wordpress validates the URI with $_SERVER["REQUIRE_URI"]. So the site Title is Changed automatically to page not found, the loop doesn't works and so on.
Is there anyway to do this?
If not is there a other possibility actually I only need a really simple redirect from "www.example.com/test/" to "www.example.com/t.php?a=1" So it's completely static i don't need patterns at all. I have already tried it with "frameset" but that looks pretty ugly and makes the process slow.
Thank you very much
Jakob
My .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# My Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^Malta/$ http://www.reisekontrast.de/Index?malta=1 [QSA,L]
RewriteRule ^China/$ http://www.reisekontrast.de/Index?china=1 [QSA,L]
# WP Rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
We need your original .htaccess file. This is an easy rewrite (redirect), but wordpress already has URL Rewriting rules. To help you best would mean we need to work cohesively with what settings you already have running. Otherwise your are just going to break Wordpress but get your URL's working.
Also, as a primer question, does your server support full override in htaccess?
Based on your HTACCESS file, I would add the section for "Custom" Rules. That way it bypasses the Rewrite Conditions that are arbitrary in this type of rewrite.
Hope this helps! Let me know if I can provide more detail or other options.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rules
RewriteRule /test/(.*) http://example.com/t.php?a=1 [NC]
# My Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^Malta/$ http://www.reisekontrast.de/Index?malta=1 [QSA,L]
RewriteRule ^China/$ http://www.reisekontrast.de/Index?china=1 [QSA,L]
# WP Rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
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>