URL rewrite query_string in wordpress - php

I have a taxonomy search form in wordpress and the link output is
http://localhost/wp/?cityid=16
But i want it to be rewrited as
http://localhost/wp/cityid/16
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
I found this but could not implement to my case. Any help please?

Try this RewriteRule:
RewriteBase /wp/
RewirteRule ^wp/cityid/([0-9]+)$ ?cityid=$1 [L]

Related

SEO friendly URL parameters via .htaccess

I want to rewrite the URLs from:
https://www.example.com/bibliorafturi/?wpsolr_fq%5B0%5D=pa_culoare_str%3AAlbastru
to this:
https://www.example.com/bibliorafturi/Albastru
Another example:
https://www.example.com/bibliorafturi/?wpsolr_fq%5B0%5D=pa_culoare_str%3AAlbastru&wpsolr_fq%5B1%5D=pa_brand_str%3AESSELTE
to this
https://www.example.com/bibliorafturi/Albastru/?wpsolr_fq%5B1%5D=pa_brand_str%3AESSELTE
So I need only pa_culoare_str to be SEO friendly.
How can I do this with .htaccess?
UPDATE:
This is my .htaccess file now:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} /(.*)/(.*)/(.*)/?$
RewriteRule ^ /%1?wpsolr_fq[%3]=pa_culoare_str:%2 [QSA,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thank you!

exclude folder in wordpress using htaccess failed

I created a folder named folder1 after entering the root. At that level of directory there's my .htaccess, I googled and I paste the following line at
..
RewriteRule ^index\.php$ - [L]
// this
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
..
But when I go to mydomain.com/folder1, it returned 404 of my wordpress?
You should post all of your code so that we can make sure there aren't other rules conflicting. Not just the part you can't get working.
Try using THE_REQUEST and try it this way and put it above your wordpress rules. So if it matches then do nothing.
RewriteCond %{THE_REQUEST} ^(GET|POST) /(folder1|folder2|folder3) [NC]
RewriteRule ^ - [L]
I found this, exclude subfolder with wordpress .htaccess and workds for me.
I put this before WordPress rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/yoursubdirectoryname1/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
and here is WordPress rules:
# 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
My complete .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/yoursubdirectoryname1/(.*)$
RewriteRule ^.*$ - [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
source: I found this code on WordPress forum.

change query string url using htaccess in wordpress

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

htaccess rewrite url rule

I'm new to htaccess and I need some help with a rewrite rule.
I wish to rewrite:
/all-accomodation/anything/ to: /portfolio-gallery/anything/
The 'anything' could be any slug.
One thing to note is that I have a page with a slug of 'all-accomodation' and when requested by itself shouldn't rewrite.
Here is my current 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
Thanks in advance,
Dave
You don't want to edit Wordpress's rewrite. Above that block, you can try:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^all-accomodation/(.+)(/?) /portfolio-gallery/$1$2 [L]
</IfModule>
This will 301 redirect all requests.

How do I remove the extension for an external file in my wordpress htaccess file?

At the moment I have the following in my 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
I've uploaded a separate .php file called contact.php that I'd like to rewrite so that users can access it via http://mydomain.com/contact instead of http://mydomain.com/contact.php
What do I need to put into my .htaccess file so that I can have this rewrite for this one file only?
Just add one line for your redirect as shown below:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^contact$ /contact.php [L] <-- New Line
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You should put this before the # BEGIN WordPress comment, since it's not WP related:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^contact$ /contact.php [L] # /contact rewrite
</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

Categories