htaccess rules for website are not working properly - php

I have website where on root i have htacess files and two folder for (blog->WP,shop->Magento).
My directory structure are like this root (htaccess,other files,blog,shop).this was my htaccess code on root
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ "http\:\/\/www\.example\.com\/$1" [R=301,L]
It works with these url's like example.com and example.com/blog ->for WP and example.com/shop-> for Magento.But now i transferred to new domain and convert site to ip base.I want to access my site like 192.168.2.36.If i change above htaccess code with ip it only works for home, for inner it gives errors.Please help how can i solve the issue.I want to access my site like IP/blog,IP/shop

Add this in your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>

Related

Redirect wordpress website to a directory using htaccess

I've a wordpress installation inside a directory "public_html/mywebsite/"
. My root directory is "public_html/". My domain wwww.mywebsite.com pointed to the root folder "public_html/". Due to some reasons, I can't point the domain to the "mywebsite" folder. But I want to load the website from the "public_html/mywebsite/" directory when wwww.mywebsite.com is called. I tried with htaccess for this implementation. But not working.
In the "public_html/" directory, I put a .htaccess file and added the following code;
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteRule ^(/)?$ mywebsite [L]
It redirects the website to the "mywebsite" folder but it returns 404 page of the wordpress website.
I modified the .htaccess of the wordpress directory like this;
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(mywebsite|mywebsite/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any idea to solve this?
I used the wordpress redirect rule based on the following link and this worked for me.
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
For more security .I made a new folder with a long random name and installed Wordpress there .To redirect visitors to that wordpress folder without them noticing anything in URL, I made a .htaccess file and wrote this in it.
<Files .htaccess>
order allow,deny
deny from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>
first part is for security, second part is redirect.I replaced "my_subdir" with the random folder, and replaced "example.com" with my website.

How to redirect or load a website placed inside a WordPress directory?

I have a WordPress website hosted at the root folder and in the same root another CodeIgniter website placed in a folder.
The CodeIgniter site is not loading now. IT shows page not found error
The URL structure will be: http://website.com - wp site and http://website.com/wi/ver1/
which means I put the CodeIgniter site in a folder wi/ver1/.
The htaccess code for the base wp site 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
And the httaccess inside the wi/ver1 directory is :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
Could you please try to help to solve this issue?
First of all check your site_url in wordpress project. Then change your RewriteRule . /index.php [L] with RewriteRule ^(.*)$ index.php?$1 [L] because it contains double backward slashes in your url .
if you want to load your codeigniter site, change base_url in config.php file, add your folder name that url
For example :$config['base_url'] = http://yoursite.com/folder_name/.

htaccess subdomain with subfolders access

I am trying to rewrite the subdomain request to a subfolder in my server using .htaccess. I want mail.domain.com to look into mail folder located in the root. I am able to achieve this with the below code
RewriteEngine on
RewriteCond %{HTTP_HOST} mail.domain.com$
RewriteCond %{REQUEST_URI} !^/mail
RewriteRule ^(.*)$ /mail/$1 [L]
This WORKS correctly. When i browse to mail.domain.com i am getting the contents of domain.com/mail/index.php.
However this doesn't work with the subfolders inside the subdomain. ie when i browse to mail.domain.com/installer it DOESN'T give the contents from domain.com/mail/installer/index.php. Instead it shows 404 error. I also tried the code from htaccess subdomain pointing . Somehow I am unable to get the output. That method also gives the same problem. What am I doing wrong?
Note:
I do not want redirect conditions. Want to achieve via rewrite rules.
I am using openshift server. created domain.com & mail.domain.com aliases.
Root folder contains wordpress with no below .htaccess rules.
Edit
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
When I remove the above wordpress htaccess all works well. So it is causing 404 error in subdomain subfolders. Please help what i can do for both wordpress pretty urls and subdomain subfolders to work?
Note: I am really sorry. Wordpress added this via web interface and i failed to notice that.
Keep your root .htaccess like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =mail.domain.com
RewriteRule ^((?!mail).*)$ mail/$1 [L,NC]
RewriteRule ^(index\.php$|mail) - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

.htaccess rule to rewrite query string to a path

I'm looking for a way to have the URL
site.com/collection/name
serve the content that is actually located at...
site.com/collection/?collection_name=name
The website is running on WordPress, and is currently using the default .htaccess rules located in the root:
# 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
Because it's on WordPress, it's currently looking for a page /collection/name that doesn't exist, and produces a 404 error.
There should be an index file under the folder "name"
If so, you can try this:
RewriteEngine On
RewriteBase /
RewriteRule ^/$ /collection/name/index.php
RewriteRule ^([a-zA-Z0-9_-]+)/$ /collection/?collection_name=$1
This is a generic rule that works in many similar occasions. Modify it to suit your website...

Subdomain htaccess issue in Magento

public_html/ # www.domain.com
public_html/subdomain # subdomain.domain.com
public_html/.htaccess
public_html/subdomain/.htaccess
I have a subdomain subdomain.domain.com
I have .htaccess file under public_html
This htaccess file contains this code:
Options -MultiViews
RewriteEngine On
RewriteBase /
ReWriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
ReWriteCond %{REQUEST_URI} !^/subdomain/
ReWriteRule ^(.*)$ /subdomain/$1
I need to install magento inside subdomain folder
.htaccess file inside this folder is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
</IfModule>
Magento Installed successfully, But I am facing a problem:
http://subdomain.domain.com/admin (this url works)
but when I hit http://subdomain.domain.com/index.php/admin its shows "No input file specified."
All internal URLs in admin are also throwing same error.
Please help me what wrong I put in my htaccess
Thanks in advance.

Categories