301 Redirect to subfolder but with input - wordpress

I want my wordpress site redirections to remember the url but place it in a subfolder.
So http://www.example.com/test123 has to redirect to http://www.example.com/voetbal/test123
And http://www.example.com/0239 to http://www.example.com/voetbal/0239
My htaccess looks like this.
RewriteEngine On
RewriteBase /voetbal/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /voetbal/index.php [R=301, L]
this makes my site go from http://www.example.com to http://www.example.com/voetbal/
but only the root.
How can i make my htaccess to remember peoples input and place it after the /voetbal/

Try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /voetbal%{REQUEST_URI} [L,R=301]

Related

.htaccess REQUEST_URI doesn't contain folder

I have site with 2 other sites in subfolders
https://example.com/
https://example.com/demo1
https://example.com/demo2
All 3 sites are actually wordpress installations.
The problem is: when I opened a page
https://example.com/demo1/testpage
I got redirected to
https://example.com/testpage
Contents of example.com/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've tried to add one more RewriteCond before RewriteRule (one line at a time):
RewriteCond %{REQUEST_URI} !demo1
RewriteCond %{REQUEST_URI} !^/demo1/(.*)$
RewriteCond %{REQUEST_FILENAME} !demo1
RewriteCond %{REQUEST_FILENAME} !^/demo1/(.*)$
But none of this worked.
So how to make it work and avoid redirect?
It's very strange but solution was to resave site url in wordpress settings on /demo1/wp-admin/options-general.php

WP - Adding Custom Rewrite Rule

I'm trying to add a custom rewrite rule for my WP site so http://example.com/?u=sample-output, is rewritten as http://example.com/sample-output.
The rewrite rule I'm trying to add is:
RewriteEngine On
RewriteRule ^([^/]*)$ /?u=$1 [L]
The existing rewrite rule is:
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
When I add it in, it gives me a 404 error when I visit the page. I'm guessing this is because of a conflict. Any suggestions on how to fix this would be greatly appreciated.
Based on your comments, put the rule above the WP rules and then you can do something like this. And all URLs that will go to the query string would have to use /start/ in it. Then make sure to ignore /start/ in the WP rules like below for all others.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^start/([^/]+)/?$ /?u=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/start [NC]
RewriteRule . /index.php [L]

htaccess rewrite : Wordpress directory + subdomain redirect not working together

I moved a Wordpress blog from blog.mywebsite.com to mywebsite.com/blog/ .
Everything was OK until I tried to redirect old links to the new location.
I want people asking http://blog.mywebsite.com/2014/09/article-example/ to find themselves in http://mywebsite.com/blog/2014/09/article-example/
But the htaccess is already completed with some rules using the keyword "blog"
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
I cannot find the way to write the rule
Today I have an error 500 with this link : http://blog.mywebsite.com/2014/09/article-example/
I would like at least to redirect to mywebsite.com/blog/ , ideally to http://mywebsite.com/blog/2014/09/article-example/
Any idea?
Thanks and good day everyone :)
You can replace your current htaccess code by this one
RewriteEngine On
RewriteBase /blog/
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/blog/$1 [R=301,L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

.htaccess add .html instead of slash(/) error

I switched my website to wordpress but now url link end with slash(/) instead of .html and i don't wanted to lose my google index so After banging my head around here and there , I have finally found a solution. i created .htaccess rule that will work globally for every page.
I just updated the .htaccess file in root with below code:
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]
Now any URL like this: /features/cart/ will automatically forward to /features/cart.html
Everything was working fine but now i am getting 404 error on those page which already have .html extension.
Please advice asap, because i am loosing my indexing and keyword ranking.
Here below is the actual code of .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.*)\/$ $1.html [R]
RewriteRule ^(.*).html$ index.php/$1 [L]
redirect 301 /about_us.html /about.html
redirect 301 /about/ /about.html
</IfModule>
# END WordPress
Site name: dailydealbuilder.com
Try reordering your rules:
Redirect 301 /about_us.html /about.html
Redirect 301 /about/ /about.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
# Rewrite rule for appending .html
RewriteRule ^(.+?)/$ $1.html [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)\.html$ index.php/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

Wordpress - Permalinks and folders (.htaccess ?)

I have a Wordpress website with permalinks with post name. Now I have a new template on a specific page that uses files from exactly the same url path, and I can't change that.
How can I make Wordpress access my requested page (example.com/meniu/) and ignore the folder name with same name? (example.com/menu/swf/)
Thank you!
This is my .htaccess. How can I add exclusions?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /club/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /club/index.php [L]
</IfModule>
You could prepend another rule to exclude only that directory:
RewriteCond %{REQUEST_URI} ^/menu
RewriteRule . /club/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /club/index.php [L]

Resources