Htaccess issue with wordpress - wordpress

I have a wordpress installed in a subfolder called blog/
I have two htaccess files, one in the root directory, one in blog folder, generated by wordpress.
The first htaccess in root directory:
# BEGIN
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(blog/.*)$
<IfModule mod_rewrite.c>
Redirect 301 "/old_page" "http://example.com/new-page"
...
<IfModule>
# END
The second htaccess in blog folder:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
<IfModule>
# END WordPress
My issue is when I navigate to http://example.com/blog/, I'm redirected to a link like that:
http://example.com/index.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlindex.htmlblog/

I have checked your Htaccess code used for the subfolder URL, it will work fine and I have modified the root directory Htaccess code for redirection.
Please try to below code for this.
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /blog/$1 [L]
SubFolder Htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

You can use the below code for the old URL to new URL:
<IfModule mod_rewrite.c>
RewriteEngine On
RedirectMatch 301 /old-page/ /new-page/
<IfModule>

Related

.htaccess issue, folder in wordpress?

I have a folder called /mf/ that is not related to the wordpress install but it is in the same root folder. When I visit the folder path (www.domain.com/mf) it gives me a 500 error. I know that this is an .htaccess issue.
I've modded my root .htaccess to do the below code but it still does not work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/mf/(.*)$ [OR]
RewriteRule ^.*$ - [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
Any advice on how to fix this .htaccess issue?
in your "mf" folder create a .htaccess file and there put all the configuration that nedded, and in the main folder-wordpress put only the wordpress part.
in th "mf" change the RewriteBase too.
main-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
the mf folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mf/
RewriteCond %{REQUEST_URI} ^/mf/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>

.htaccess rules to have wordpress in root and cakephp in subfolder

i installed wordpress in the root directory of my FTP, and then in a subfolder I install cakephp, however I have a problem with htaccess.
www/
.htacess
(wordpress)
/folderCakephp/
.htacess
(cakephp)
Wordpress 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
Cakephp root htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Cakephp app/ htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Cakephp app/webroot/ htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
the problem is that when I go on www.domain.com/folderCakephp/ I have a Wordpress 404
In the directory where WordPress is installed, i editing the .htaccess file and i have add the following line. (CakePHP subdirectory will be called "cake")
Wordpress .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^cake/(.*)$ /cake/$1 [L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
/cake .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cake
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
That’s it. You’re good to go.
Visiting example.com in the browser will open your WordPress website, while example.com/cake/, depending on how you configured it, will open your CakePHP app.
I believe the issue is the last line in your WordPress rewrites
RewriteRule . /index.php [L]
This rewrites everthing that isn't picked up by another rule to WordPress. I think you want to change this to match everything but the cakePHP folder using a negative match. I have not tested this, but it should be something like
RewriteRule (?<!folderCakephp). /index.php [L]

Index of folder in wordpress .htaccess

When I use the following url "http://www.tuto3d.netai.net/wordpress/" in my navigator I access normally my wordpress site but when I use http://www.tuto3d.netai.net/ I get the index of folder instead and a link to wordpress folder. I want to redirect in my .htaccess the http://www.tuto3d.netai.net/ to the "http://www.tuto3d.netai.net/wordpress/"
and this is my my .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Thank you in advance
Have this rule in your DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteRule ^$ /wordpress/ [L,R=301]

Wordpress : redirect url to a subdomain

I have just hosted a wordpress website on godaddy .
I am having a situation .
I have a website www.example.com/cnI want when someone open this page this page should redirect to a sub domain cn.example.com .
I am hosting wordpress app first time kindly do let me know how can I do that .I am Python Guy I don't know about htaccess
I tried using header('location:cn.example.com') in the index.php file but the problem is cn.example.com and example.com/cn both pointed to the same wordpress app . So I am getting problem .
Please help me to figure out this problem .
*Updated Htaccess *
RewriteCond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
RewriteBase /
RewriteRule ^(.*)$ http://mobile.example.com/ [R,L]
##END MOBILE
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
</IfModule>
<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
# 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
Assuming you are letting Wordpress load from the differing hostname, you can handle the rewrite by having the following in your .htaccess file found in the root of your Wordpress install:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
It will match /cn or /cn/ exactly from any host that is not already cn.example.com (prevent looping), and redirect to http://cn.example.com using a 301 HTTP response.
You can test these rules here: http://htaccess.madewithlove.be/

Wordpress + Codeigniter htaccess confusing

I have Wordpress installed in the root directory with the following 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
and I have Codeigniter installed in a sub-directories named members, with the following htaccess :
RewriteEngine on
RewriteBase /members/
RewriteCond $1 !^(index\.php|images|templates|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
When I try to access any controller via : site.com/members/controller/function I get the Wordpress 404 error page
In your CI config.php, set your base url as
$config['base_url'] = 'http://site.com/members/'
and change
RewriteBase /members/
to
RewriteBase /
in your CI .htaccess file. This way when you access CI, it doesn't look in the root (which is WP), it goes straight to it's directory and bypasses WP.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cidir
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>

Resources