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
Related
My server is Ubtuntu 18.04, OpenLiteSpeed, and Wordpress. With all plugins disabled, and using the default theme we are unable to publish or update posts/pages. This question looks similar to a lot of other ones but none of their solutions are working for me. My understanding of this issue is that maybe our htaccess file isn't being respected by OpenLiteSpeed, even though it is configured to do so. I have not edited the .htaccess file at all. Here are its contents:
# BEGIN LSCACHE
# END LSCACHE
# BEGIN NON_LSCACHE
# END NON_LSCACHE
### Forcing HTTPS rule start
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### Forcing HTTPS rule end
# 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 also get 404 error messages in the console for urls in this path: https://example.com/wp-json/wp/v2/*
I have tried updating the permalink structure multiple times to no avail, unless I add index.php to the structure. For example https://example.com/index.php/%postname%/. This allows us to visit posts, update them, etc.
It's great that we can have it working, but that index.php in the URL is just so darn ugly. What do I need to do to get rid of it?
If you are using rewriterule tab in webadmin console, instead of .htaccess
you will need to change the rule
from
RewriteRule ^index.php$ - [L]
to
RewriteRule ^/index.php$ - [L]
save and restart it.
there is slightly difference for rewrite rule when you place it in different place, mostly a forwarding slash like above one.
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.
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.
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/
So, I'm trying to add my own RewriteRule in addition to what Wordpress already has. A little backgroun. The site I am working on is built off of a custom CMS, but also has a blog that is powered by WordPress. So, heres what I have thus far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ /locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I also got rid of a couple lines of the Wordpress Rewrite code that seemed unecessary (everything still works....I think). But yeah, it seems like it is overwriting the rule that I wrote. Help?
Oh, also, I just tried to get rid of the . that is before /blog/index.php [L] and replaced it with just a ^, it worked...kind of. It loaded the blog when I went to /blog/, but when I went to something like /blog/author/admin, I got a 404.
I think you need to add the last flag [L] after your new rule, otherwise processing will continue and your request will be rewritten to '/blog/index.php'.
RewriteRule ^locations/(.*)$ /locations2.php?info=$1 [L]
Have you tried to remove the RewriteBase / and the slash before locations2.php ?
Something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
If the blog gets unreacheable, move RewriteBase / to after the custom rewrite. Also, I believe that if the blog is in a sub-directory, the RewriteBase should be RewriteBase /blog/