Rewrite the url using htaccess in wordpress - wordpress

I am new to WordPress, creating the custom taxonomy for location in the my current URL
http://localhost/myproject/locations/us
i am need to change the URL like in that location place rename to my-project
i am trying to change the URL using Rewrite rule in ht-access file
RewriteRule ^my-project/us?$ http://localhost/myproject/locations/us [R=301,NC,L]
but its not working any one help me?

Custom .htaccess in WordPress site can bring unexpected results.
You may instead use WordPress' specific Rewrite API
Edit: if you need to use .htaccess insert your rules before the WordPress' ones.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^my-project/us?$ http://localhost/myproject/locations/us [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This is the final .htaccess code, i tested this solution here and it works correctly.
If this solution didn't solve your case maybe there is a problem elsewhere.

Related

How to use mod_rewrite without clashing with Wordpress

So I have Wordpress installed, let's call the domain test.com. The .htaccess that wordpress created in the default directory (the one that is one level above wp-content) is
# 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 want to add another rule, which if triggered, should case Wordpress to not rewrite. So for instance, suppose I want test.com/nochange to redirect to test.com/script.php, instead of doing the normal Wordpress redirects. Normally the .htaccess for this would be
RewriteRule ^nochange$ ./script.php [NC,L]
But what happens is that Wordpress ends up running anyways, and of course a 404 not found occurs. If I removed the Wordpress .htaccess components, everything works. What do I do to get them to work together?
Ah, I just needed to use the END tag.

Additional .htaccess Rewrite Condition with Wordpress

I wish to remove part of a pluggin's URL in Wordpress. I have a standard permalinks setup but have three URLSs with a similar iffy prefix I wish to clean up:
Currently I have
http://domain.com/?pfwk_cats=works
And I require:
http://domain.com/portfolio-works
My current htaccess looks like:
# 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 solution was to add:
RewriteEngine On
RewriteRule ^portfolio-([^/]*)$ /?pfwk_cats=$1 [L]
But it does not kick in? Any ideas? I assuming the Wordpress Rewrite rules are messing it up? Help much appreciated!
You need to make sure your custom rule is above the #BEGIN WordPress line. The WordPress rewrite rule is a "catch all" so if you put yours below, it will never get there.
Also, don't forget to restart Apache: service httpd graceful
~tommy

Wordpress htaccess modrewrite

This is my htaccess for wordpress
# 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 create a category named "hotels"
I like to change my url via mod rewrite apache module.
My current url like this
http://www.mydomains.com/hotels?state=newyork&country=us
But I want url like below:
http://www.mydomains.com/hotels/us/newyork
How can i achieve this?
I tried to get url like this:
http://www.mydomains.com/hotels/newyork from http://www.mydomains.com/hotels?state=newyork
so i used this line after the rewrite rule but it was not worked.
RewriteRule ^hotels/([^/]*)$ /hotels/?state=$1 [L]
Can some one please help me?
Thanks in advance
Is there a particular reason you are trying to change permalinks via htaccess? This is more effeciantly done thru the wordpress dashboard under
Settings> Permalinks
You can choose a custom permalink structure or choose from the pre selected ones given thru wordpress.
Put this before the RewriteConds:
RewriteRule ^hotels/([^/]+)/?$ hotels?state=$1
You don't want the [L] flag because it prevents Wordpress from ever processing it.

Wordpress htaccess redirect issue

I'm trying to redirect a few pages to different pages. This should be simple, but I'm missing something simple, apparently.
I have a wordpress install on a subdomain. Wordpress's generic htaccess is this:
# 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 want to redirect /farm-partners/ to /farm-partners/emilys-produce/. I'm trying to do so using the following code:
RewriteRule ^farm-partners/?$ /farm-partners/emilys-produce/ [L]
However, opening /farm-partners/ doesn't redirect, it just loads that page. What am I missing?
Use the WordPress Redirect plugin and don't mess with the htaccess.
What you are missing in your RewriteRule though, it telling it that you want an external redirect
RewriteRule ^farm-partners/?$ /farm-partners/emilys-produce/ [L,R=301]
If you use a RewriteRule, make sure it is outside the comments that indicate which parts of the file may be edited without any notice (i.e. outside the #comments marking WordPress's section of the file. Similarly if you are using W3 Total Cache or a similar plugin.)
Try this:
RewriteRule farm-partners/$ /farm-partners/emilys-produce/

htaccess a dynamic URL

I'm using Wordpress with a plugin and it's currently making urls like this: http://www.example.com/?name=the-office
I would like to redirect all similar urls to http://www.example.com/name/the-office
Current 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
I tried a few things and nothing seemed to work, maybe I'm need to place the RewriteCond in the IfModule? Not sure, htaccess is foreign to me. Thanks in advance.
If you'd like a workaround that is much easier to accomplish - simply login to your wordpress admin panel, go to settings, then permalinks and there you can select how your links will look like. Select the last option (Post name) to get only post names in the urls.

Resources