Static redirection in .htaccess with rewriterule - wordpress

I should make some url redirections (no variables to pass) in .htaccess but I don't want to let see the destination url. How can I make?
I've already tried to use Redirection instruction like this:
Redirect /en/folder1/url1 /en/folder2/url2
But in this way the destination url is visible. So I started to try to use RewriteRule like in this example:
RewriteRule ^/en/folder1/url1$ /en/folder2/url2
but I've always error page as result.
P.S. This code is inside a .htaccess file with the default Wordpress url rewrite code.
EDIT. This is the complete .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^en/folder1/url1$ en/folder2/url2
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

You need to remove the leading slash from your Rule's pattern
RewriteEngine on
RewriteRule ^en/folder1/url1$ /en/folder2/url2 [L]

Related

removing part of the url using .htacess but redirect to original URL internally

I have modified the href link using preg_replace
for example the original link is
http://testdomain/test/save20
to
http://testdomain/save20
but when I click on this link I still get http://testdomain/test/save20
besides I only want to change it in the browser like
http://testdomain/save20
but internally it should continue to use the url
http://testdomain/test/save20
I have tried in .htaccess like this
RewriteRule ^test/([^/]+)/?$ /test=$1 [NC,L]
but it doesn't seems to have any effect.
The full code in .htaccess is like 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]
RewriteRule ^test/([^/]+)/?$ /test=$1 [NC,L]
</IfModule>
# END WordPress
You can use the following rule
RewriteEngine on
RewriteRule ^([^/.]+)$ /test/$1 [L]

htaccess Redirects with Wordpress

I am working with a GoDaddy Hosted Wordpress website.
I have users that will attempt to go to <mywebsite.com>/jobs and I need them to be redirected to <mywebsite.com>/newpath/corporate-opportunities/.
I am under the impression that I can place rewrite rules in the .htaccess file that exists at the root of my GoDaddy Hosted installation. I have the following in place:
# 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
<IfModule mod_rewrite>
RewriteEngine on
RewriteRule http://<www.mywebsite.com>/jobs http://<www.mywebsite.com>/newpath/corporate-opportunities/ [R]
</IfModule>
The first set of rules (within the Wordpress Begin and End comments) is what is commonly put in place for the Wordpress 'permalink' URL rewrites so they are pretty. The rewrite rule after the Wordpress block is how I am attempting to do the redirection.
I am not able to get it to work.
You need to move your redirect rules above the WordPress rewriting ruleset, so that they are seen before-hand. Additionally, the RewriteRule pattern (the first part) is always the request URI, and not the fully-qualified URL - as you are working with one domain, you also do not need to use the fully-qualified URL in the substitution part. Lastly, you need the L flag to stop processing at that point.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^jobs/?$ /newpath/corporate-opportunities/ [R,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

Wordpress messed up our htaccess redirect, how to modify to work with Wordpress' htaccess code?

We had several domains parked on top of our main website. This was a normal HTML website and we used the following redirect so that the domain would 301 redirect to the proper url to avoid getting dinged by Google.
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
So the above htaccess code just rewrites the url to www.ourmainsiteurl.com, which is what we want.
Now here's the problem... we installed Wordpress and it has the following default htaccess code:
# 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 to add my redirect code in but that broke Wordpress. Can anyone tell me what I need to use to make this work?
Simply put I want all the parked domains (ie: parkedurl1.com, parkedurl2.com, etc) to be redirected to www.ourmainsiteurl.com with the htaccess file.
Make sure the redirect is before any wordpress rules:
rewriteCond %{HTTP_HOST} ^ourmainsiteurl\.com$ [NC]
rewriteRule ^.*$ http://www.ourmainsiteurl.com%{REQUEST_URI} [R=permanent,L]
# 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 it's still not working, check to see if wordpress has something turned on that is redirecting, or adding/removing the "www" from the hostname.

How do I add additional mod_rewrite rules on a wordpress site?

I have uploaded a file 'events.php' to my wordpress site (the wordpress is installed in my root directory).
I would like to make a mod_rewrite to this file so that one may go to mydomain.com/events
I tried simply doing something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule %events$ events.php [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Which didn't work.
I also found I could add rewrite tags via wordpress using its inbuilt functions like so:
add_rewrite_rule('^events?','/events.php','top');
This also didn't work - I simply end up on my default 404 page as though its reached a non-existent page within my wordpress.
What am I missing here?
Correct me if I’m wrong, but if all you want is for someone who goes to example.com/events to be directed to example.com/events.php, than you can just do a redirect like so.
Redirect 301 /events http://www.example.com/events.php
Try the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^events /events.php [L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The directive that you had set for the URL would not match:
RewriteRule %events$ events.php [L]
Also, the directive is now below the condition that checks for an existing file, so that it never matches a direct request for events.php.

How do I combine WordPress permalink code and .htaccess redirect?

I'm trying to combine the following code so that the WordPress permalinks work in the main directory, waringis.com (top code) and a second domain, burrowpress.com, is redirected to the subdirectory 'waringis.com/burrowpress' (bottom code) -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} burrowpress.com$ [NC]
RewriteCond %{REQUEST_URI} !^/burrowpress/.*$
RewriteRule ^(.*)$ /burrowpress/$1
Right now permalinks are working in WordPress and the redirect works but images have to be direct links to waringis.com/burrowpress/images/ instead of burrowpress.com/images/ - Any help is much appreciated...
You need to swap your code blocks around. The [L] flag on the WordPress rules are stopping execution of the file at that line in their code since your special path would "pass" the WordPress REWRITE_COND statements:
RewriteEngine On
RewriteCond %{HTTP_HOST} burrowpress.com$ [NC]
RewriteCond %{REQUEST_URI} !^/burrowpress/.*$
RewriteRule ^(.*)$ /burrowpress/$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You don't need two RewriteEngine On statements, but since WordPress is able to rewrite your .htaccess file (depending on how you have it setup) you might want to leave it. If you are updating your file manually, you can remove the second RewriteEngine on directive.
The important part is that I moved your special rules ahead of wordpress.
I'm not a .htaccess expert but i would say that you don't need to include RewriteEngine On twice that you can put the redirect code in the if statement. So you want to redirect to the subdomain but not have your images be kept in the subdomain is this correct?

Resources