How to setup Subdomain directories with .htaccess - .htaccess

I have subdomain, got error 404 while clicking on links. I want to be able to click on each link without getting any error messages. How can I setup the .htaccess file? currently using codeIgniter.
Here's the situation
Ex:
mysubdomain.website.com -> mysubdomain.website.com/gallery1 = display error 404
mysubdomain.website.com -> mysubdomain.website.com/gallery2 = display error 404
NB: BTW I Don't want to redirect mysubdomain.website.com to website.com/mysubdomain/gallery1
Any helps migh appreciate
Thanks in advance!

My .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|phpmyadmin|robots\.txt|ckeditor|css|js|favicon\.png|captcha|img|uploads)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Anything other than given values "images", "phpmyadmin" etc. will be looked up in config/routes.php
So:
http://127.0.0.1/css/style.css
Will return file at www/css/style.css
http://127.0.0.1/anything
will be taken as CodeIgniter link
Edit: Don't forget to update your config file with
$config['index_page'] = '';

Related

.htaccess load index.php but not other .php files

I want to configure the .htaccess file to work the following way:
If the visitor tries to open a url with an existing folder name, redirect to main page (index.html).
I have the following rules for that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !/index.html$ [NC]
RewriteRule ^data/existing-folder-1$ https://example.com [R=301,NC,L]
RewriteRule ^data/existing-folder-1/$ https://example.com [R=301,NC,L]
RewriteRule ^data/existing-folder-2$ https://example.com [R=301,NC,L]
RewriteRule ^data/existing-folder-2/$ https://example.com [R=301,NC,L]
</IfModule>
And it's working fine.
If the user tries to open a forbidden type of file (like .php), send to 403.
RewriteCond %{HTTP_REFERER} !^https://example.com [NC]
RewriteRule \.(php|log|htaccess)$ - [F,L,NC]
And it's also working fine.
I don't want users to see the contents of the folders, so I have this line:
Options -Indexes
I think that's all the important details to see the background.
I have a /rd folder with a simple index.php file to redirect URLs:
$url=$_GET["url"];
if (empty($url)){
//
} else {
header("Location: " . $url, TRUE, 308);
// later on with special functions
exit();
}
Such a link on my page looks like this:
https://example.com/rd/?url=https%3A%2F%2Ffoo-bar.com%2Fexample
Please note, that index.php is not written after /rd/ and before ?url. But if it's easier to solve this issue, I can modify it.
And now the problem comes here:
When I click on such a link through my website, it works perfectly.
But when I copy this redirect-link, and try to open in a new tab/window, it says 403 Forbidden. I think because #2 rule to disable access to .php files outside my domain.
Since I want to share those redirect links, I want them to be able to open when copy-paste the links.
I also don't want anyone to access any of my .php files - so it's not an option to remove rule #2.
How can I solve this issue? How can I enable to use the redirect links "alone", while keeping the rules to prevent access to files/folders?
Thank you.

Using .htaccess is giving 500 error but working for file

I am not an expert using .htaccess but here is my scenario:
My .htaccess is in the root.
The only content is below.
To access the pdf file is working fine but not when I am trying to access the file with parameters that is going to return data or send data.
I know I am missing something but what?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^admin$ login.php
RewriteRule ^admin-system/balance/get$ source/Support/Action.php?action=balance-get
RewriteRule ^admin-system/balance/list$ source/Support/Action.php?action=balance-list
RewriteRule ^admin-system/balance/set$ source/Support/Action.php?action=balance-set
# This one is working fine.
RewriteRule ^admin-system/terms$ app/helper/files/term.pdf
Options +Indexes
</IfModule>
HTTP 500 - when talking about htaccess - is a syntax error. IMHO, just remove the following line:
Options +Indexes
It's highly possible, that Options is not allowed there - the apache error log will give you a clue about it.

How to write .htaccess rewrite rule to solve 404 error when angularjs html5mode is enabled

I am new to AngularJS and PHP. In the application i am working on, I have enabled html5mode in angularjs using following things:-
-- Added base href in /myapp/index.html
<base href="http://localhost/myapp/" />
-- Added following at the end of config function.
$locationProvider.html5Mode(true);
When I access my application using following url: http://localhost/myapp ,
It does not append any # in browser url. I can navigate to any other route successfully. Route url is http://localhost/myapp/category/1
But when I refresh the page, above url gives me 404 error. I understood that, server trying to find file at location /myapp/category/1. I read at other places writing .htaccess rule will solve this problem. I tried all those options. Nothing worked for me.
I am using xampp and location of .htaccess file is /htdocs/myapp/.htaccess
.htaccess file is accessible, because if I add any junk data in it, url throw error.
Please help me on this. I need server to return url as it is so that angularjs can route pages correctly. Please help me to write .htaccess rule. mod_rewrite is already enabled in httpd.conf file of apache.
I can able to find solution for this. My .htaccess file will look like below
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.html
RewriteCond %{REQUEST_URI} !.*\.(map|cssĀ¦js|html|png)
RewriteRule (.*) index.html [L]
</ifModule>

.htaccess rewrite resulting in 404 error

I am trying to create search engine friendly URLs with the following .htaccess and it is directing to a 404 error page no matter what I try.
This is on a Host Gator shared account, if it makes any difference. The directory is (document root)/blog, the .htaccess file is located in the directory "blog."
Example URL would be http://examplesite.com/blog/category/announcements.Here is the .htaccess file contents:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)/$ index.php?category=$1
Any ideas why this is happening?
RewriteRule ^category/([a-zA-Z0-9]+)/*$ index.php?category=$1 [R=301,L]
Forget the preceeding slash?
RewriteRule ^category/([a-zA-Z0-9]+)/$ /index.php?category=$1

url re writing in .htaccess in codeigniter app

I have a codeigniter app and i wanted to remove index.php from the URI. so from the codeigniter wiki i used this script.
It stopped working once i change a config, after this change all my urls only returned home page. No matter what link i used, it only gives me the home page of my site. So i reverted it back to index.php but the server still works the same way. I tried deleting the .htacess file completely then update it with the new one which actually works but even then its working the same way. (all urls redirected to home page) Im totally out of clue, on whats wrong with my script or server.
P.S : when using .htacess i did make $config["index"] to be blank.
UPDATE
Now i removed everything else from my .htaccess file and i have only this which is the essential part to remove index.php from uri segment
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Even with only these all my urls are taking me only to the home page. I am clueless as of whats happening.
In your app/config/config.php try changing the value of:
$config['uri_protocol'] = 'AUTO';
to:
$config['uri_protocol'] = 'REQUEST_URI';
If still not working, try the remaining options (PATH_INFO, QUERY_STRING, ORIG_PATH_INFO).
Your ErrorDocument line is inside <IfModule !mod_rewrite.c> which to me looks like you don't have the mod_rewrite module installed. (If you did, that line would be ignored.) The ErrorDocument 404 /index.php line is a hack to get you to the /index.php file in case a request comes in for a file that doesn't exist.
To set the 404 page in CodeIgnitor, you need to edit your routes.php file.
$route['404_override'] = 'general/not_found';
More details.

Resources