WordPress & .htaccess - wordpress

I have a website under WordPress where I've created a new page www.foo.com/section/
The idea is to create a permalink like www.foo.com/param1/type/param2 and with .htaccess use a rewrite rule to: www.foo.com/section/?var1=param1&var2=param2&var3=type
RewriteEngine on
Options +FollowSymlinks
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2
I got it working in my old web but in the WordPress crashes.
#My rules -> copy&paste
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2
# 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 only got a beautiful WordPress' 404 page
I've read several questions here but no one helps me.
Thanks for your time and best regards,
R.
13 Jan
I've created a simple test to check it.
The new structure works with a test case without problems:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^lol/$ project/ [L] #Rule 1
RewriteRule ^foo/$ test/ [L] #Rule 2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Rule 1, I've created a subfolder in WordPress root, named "project" with an index.php echoing "Hi dad" and when type www.foo.com/lol/ it loads that script and echoes the word.
Rule 2, I've created a new WordPress page, www.foo.com/test/
with a simple string to show, but when I write www.foo.com/foo/ it gives me error 404. It seems that the redirection to a wp pages doesn't works as I expected.
Disclaimer: Of course www.foo.com/test/
Now I'm stucked.
Thanks for your previous responses and future help.
Best regards,
R.
14 Jan
I have new news :)
The new .htaccess that works is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_\s-.()&]+)/alternator/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=A [L]
RewriteRule ^([a-z0-9_\s-.()&]+)/starter_motor/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=M [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Instead redirect to "elecfinder/" in the .htaccess I'm pointing to "?page_id=554", at least it doesn't gives me error 440
I'm working on an alternator and starter motors web.
I have a URL that is http://www.elecfinder.com/hitachi/starter_motor/s114850 that really is http://www.elecfinder.com/info/?supplier=hitachi&ref_num=M&reference=s114850, here I load the reference info.
http://wp.elecfinder.com/elecfinder/?reference=s114850&supplier=hitachi&ref_type=M is that web in wp, so my idea is to redirect http://wp.elecfinder.com/hitachi/starter_motor/s114850/ to this.
Now I'm able to redirect http://wp.elecfinder.com/hitachi/starter_motor/s114850 to http://wp.elecfinder.com/elecfinder/?page_id=554&supplier=hitachi&ref_num=M&reference=s114850 but there are 2 problems:
It changes the url to http://wp.elecfinder.com/elecfinder/ instead maintain wp.elecfinder.com/hitachi/starter_motor/s114850
Misses the GET parameters "reference","supplier" and "ref_type"
Thanks for your time.
Best regards,
R.

Try the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_\s-.()&]+)/(section1|section2)/([a-z0-9]+)$ section/?var1=$1&var2=$3&var3=$2 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Always put your rules after RewriteEngine on.
And, in this case (WordPress), be sure to put your rules before WordPress' rule (it is here to redirect everything to index.php because WordPress has a front controller and it manages rewriting itself).

Related

subfolder wordpress htaccess

I have a ubuntu server that has a wordpress installed on with link "https://gditac.com"
after that I installed another wordpress on subfolder like "https://gditac.com/news" but the problem is the second website redirects on first and show 404 not found page. I searche a lot but couldn't solve my problem.
here the htaccess for the root website :
# 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
and here the htaccess for subfolder website :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /news/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /news/index.php [L]
</IfModule>
# END WordPress
any idea whats going on?
I think best way is to create a subdomain e.g. news.gditac.com, install there your wordpress and make a permanent redirect from https://gditac.com/news to https://news.gditac.com
If you really want to install it on a subfolder then read this article:
https://wordpress.stackexchange.com/questions/134839/is-it-possible-to-install-wordpress-within-wordpress-installation
Alex

Wordpress not redirecting properly (Forbidden)

At some point I changed my Wordpress URL under Settings -> General. This created a lot of problems that are mostly fixed. However, my site's Url is "example.com/guiacentros/" and that works, but when users wrote "example.com" it also used to work, and now they get a "Forbidden - You don't have permission to access / on this server". Is this an error with the htacces file? This is the current htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /guiacentros/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /guiacentros/index.php [L]
</IfModule>
# END WordPress
I'm a bit confused because there's a second htaccess file one level above, that looks 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]
</IfModule>
# END WordPress
I'm not sure why there's two, but I remember adding the second one fixed some issues.

How to remove specific subdirectories in .htaccess file

Even after extensive research I was unable to resolve following redirection. I tried tons of examples, but with no luck.
From this URL:
http://www.example.com/store/product/name
I would like to get:
http://www.example.com/name
Problem is that the only known string is "store". Other strings "product" and "name" could contain letters, numbers and "-" or "_" characters.
I am testing it on live website and also on this tester: htaccess.madewithlove.be
One of the examples I used:
RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
This seems to work on above tester website, but not in real environment. I think there is something wrong with the regexp and second parameter is not properly returned or I am missing something else.
I should also mention that the website runs on Wordpress and in .htaccess file there is also following section created automatically by 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
Thanks for your help!
Have your rule like this i.e. redirect before internal WP rule:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^store/([^/]+)/([^/]+) $2 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Redirect 301 all files from a folder to one file?

Good day everyone,
On my Wordpress website, I had a plugin that transfered external links through virtual site.com/go/abc123xyz style links.
I have removed the plugin but obviously, when I checked G webmaster tools, there were many Not Found errors for all of those virtual links.
All I wish to do is redirect all of those /go/links to one particular external link. I'm looking for a redirection rule which will redirect all links from the virtual /go/ folder to my specified link.
Would be really thankful if anyone can help me. Thanks!
Try adding:
RewriteRule ^go/(.*) www.mysitedotcom/out/link.php?id=$1 [R=301,NC,L]
To your default 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
So it should look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^go/(.*) /out/link.php?id=$1 [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I hope that answers your question and helps you.

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.

Resources