How to solve sub-directory issue on hosting server - .htaccess

I hosted a website to a sub-directory in a hosting server.
But it is redirected to the main domain when I try to navigate to the sub-url of the website.
So, I added the .htaccess file to solve this problem.
The .htaccess file is the following.
RewriteEngine On
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
But I am getting the problem continuously.
Please let me know how I can solve it.

You can write the following contents to your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-directory/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-directory/index.html [L]
</IfModule>

Related

Htaccess file not working on phpmyadmin.ovh.net

I use codeigniter for my website buliding, after following the process to remove index.php file, everything work properly on localhost but when i host my site on phpmyadmin.ovh.net it's not working anymore, i can't reach any link. Can somebody help me ?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

GoDaddy + CodeIgniter + subdomain

I'm attempting to remove index.php using the CodeIgniter framework (hosted with GoDaddy - Linux), which is currently installed to: example.com/ci
I've already declared the base_url in application/config/config.php as http://example.com/ci/.
The following is my latest test input for .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
Keep in mind that the domain CI is installed under is not my hosting root. The actual path for the CI folder would be: root/mydomain/ci
After spending the better part of the day today trying a plethora of "solutions", I'm beginning to wonder if this is possible to do with GoDaddy at all, or perhaps my situation is somehow unique.
Any advice would be greatly appreciated!
EDIT: The closest I've come to fixing this issue is using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /clone/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^index.php/(.*)$ [L]
</IfModule>
.. while setting my base_url to mydomain.com/clone/ (using http:// of course) and removing index.php from index_page. Navigating to mydomain.com/clone works fine but navigating to the two pages that are part of the software results in a 404 page.
An answer to your comment, you need to add a rewrite condition to access the sites/ directory. CodeIgniter is looking for sites in the controllers folder.
RewriteCond $1 !^(index\.php|sites)
You can also add the names of your resource folders like images/video etc.
Change this
In your config.php
$config['base_url'] = '';
$config['index_page'] = '';
then in .htaccess
RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
or else you can use your .htaccess too
EDIT 01
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

htaccess rewrite rule for multiple pages

this seems so simple, but it's not working for me.
I am trying to have both show.php?id=$1 and producer.php?id=$1 rewrite as friendly URLs.
The first one works perfectly, the second does not. If I remove the first, the second works fine.
What am I doing wrong here?
My code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /show.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /producer.php?id=$1 [L]
</IfModule>
Thanks in advance!
Your problem is quite simple.
You cannot have more than one rewrite rule for the same directory, you would need to have a separate folder for each IE. have a folder called "show" and have the htaccess file that contains the rewrite data for show.
.htaccess for show folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /show.php?id=$1 [L]
</IfModule>
Then have another folder called "producer" with the 2nd rewrite rule.
.htaccess for producer folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /producer.php?id=$1 [L]
</IfModule>

My .htaccess pretty url not working which is in localhost (local machine with xampp)

I need to rewrite this url :
http://localhost/blog/post.php?id=48
into
http://localhost/blog/post/48
which is in localhost of my xampp.
I have created .htaccess file and wrote the below code to work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([0-9]+)/?$ post.php?id=$1 [NC,L]
</IfModule>
I have tried redirection and all other stuff. Everything is working but my rewrite rule alone not working. I've searched and tried all options but i couldn't succeed. Plz anyone help me out on this!!
Finally its working with below code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ # This is the thing which made me struck with this
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([0-9]+)/?$ post.php?id=$1 [NC,QSA]
</IfModule>
The ^post is your problem, this implies that post is the first part of your path, which it's not - blog is. Have you tried ^blog/post...:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/post/([0-9]+)/?$ blog/post.php?id=$1 [NC,L]
</IfModule>

.htaccess and subdomains

Hey Folks am seemingly having problems with .htaccess files.
The problem:
I have a wp install in the root directory. In a sub-directory (not a domain) there is Modx. When I enter the url to the root/modx the url is treated like a wp link and it goes back to the homepage. In other words I think the .htaccess is overriding.
The main directory (wp) has this .ht file (after digging around for a solution)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^office/.*$ - [PT]
# BEGIN WordPress
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
This is the one in the subdirectory
RewriteEngine On
RewriteBase /cms
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
well you could add the following rule to your wp .htaccess just before the RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} !modx

Resources