Codeigniter Wildcard Subdomain - .htaccess

How can I make a wildcard subdomain with codeigniter? I have try anything on google and this site. But it wont work, if not 500 error page it will return nothing (I mean no effect) because I got this on my .htaccess before :
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
I think it always conflict with that one above, btw what I desired to be is :
example.com/page => example.com/page (without subdomain will just be normal, with no www and no index.php)
abc.example.com => example.com/abc-channel
exc.example.com => example.com/exc-channel
abc.example.com/my/foo/page => example.com/abc-channel/my/foo/page
All will generated with no redirect.

Related

How to render same page with different url using htaccess

I have new domain and for now I want to render all url to home page.
eg.
abc.com/abc
abc.com/abc/xyz
abc.com/abc/xyz/123
abc.com/abc/abc/xyz/123/so_on
also url will show only current home page ( index.html (or .php) ) instead of
"Not Found, The requested URL /index.php was not found on this server."
How can I do that using htaccess?
You can use a rewrite rule in .htaccess
RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]
This will send all requests to index.php file(or you can change it to index.htm etc.)
also you can bypass static files like css/js and etc:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Restrict HTTP access to single page with .htaccess

I have this .htaccess file:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Can I force all HTTP access attempts to serve a specific page (e.g. /https-required.html) while processing HTTPS access normally?
Here is an example of the behaviour I expect, with some variation tolerated (for instance, if /https-required.html can only be served over HTTP, that's acceptable):
http://www.ex.com/ => http://www.ex.com/https-required.html
http://www.ex.com/valid-page.html => http://www.ex.com/https-required.html
http://www.ex.com/invalid-page.html => http://www.ex.com/https-required.html
http://www.ex.com/https-required.html => http://www.ex.com/https-required.html
https://www.ex.com/ => https://www.ex.com/
https://www.ex.com/valid-page.html => https://www.ex.com/valid-page.html
https://www.ex.com/invalid-page.html => https://www.ex.com/404.html
https://www.ex.com/https-required.html => https://www.ex.com/https-required.html
I wish to restrict the whole site to HTTPS but for that I must necessarily account for HTTP access attempts. I think I can disable HTTP completely, with something like
SSLRequireSSL
but that would yield a miserable experience for accidental HTTP access. The more common solution to this problem is to simply redirect http:// to https:// with something like
Redirect permanent / https://www.example.com
or
RewriteCondition %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
but I am specifically looking to avoid this redirect.
You can use it like this:
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule !^https-required\.html$ /https-required.html [L,NC,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

.htaccess Rewrite Rules online and localhost

On this website and on wamp localhost
http://www.aproapetot.ro/page.php?categ_id=1&id=1
http://localhost/aproapetot-backup/page.php?categ_id=1&id=1
I tried to build the .htaccess, but without any success.
This is what I wrote for online website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
and this for localhost
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /aproapetot-backup/
RewriteRule index.php index.html
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
Someone please give a little help.
It's a website with jokes so after .ro/page.php?categ_id=1&id=1 I have a category(1) and subcategory(1).
I want to have like this
.ro/jokes/doctors instead of how is now.
I'm not entirely sure what you want based upon the htaccess content, but what I do understand is that you want /jokes/doctors is rewritten to /pages.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !pages.php [NC]
RewriteRule ^(.*)$ /pages.php [L]
The above code will rewrite all requests to pages.php, as long as:
%{REQUEST_FILENAME} "!-f": The file itself does not exist on the server.
%{REQUEST_FILENAME} !pages.php: The request is not made to pages.php (meaning that it already has been rewritten)
Finally you can use PHP to obtain the parameters using:
/* Get all parameters from the URL */
$_GET['path'] = rawurldecode( $_SERVER['REQUEST_URI'] );
/* Remove double slashes and backslahses and convert all slashes and backslashes to '/' */
$_GET['path'] = preg_replace( array('#[/\\\\]+#', '/(\/\.)+(\/)/'), '/', $_GET['path']);
$_GET['path'][0] should contain "jokes"
$_GET['path'][0] should contain "doctors"
==edit==
Redirecting using htaccess (not the best method)
Redirect 301 /page.php?categ_id=6&id=0 /anecdotes
Redirect 301 /page.php?categ_id=1&id=1 /jokes/doctors
PHP (or other server side script). You can perform a check if the url is in fact having numbers (see $_SERVER['REQUEST_URI']) and ifso, add some header redirection to your page.
<?PHP
header('Location: www.aproapetot.ro/' . $cat . '/' . $subcat );
?>

Add get variables to url throung htaccess file

I want to add one get parameter to the every url on my wprdpress website except the index page.
For example,
Consider website name to be www.example.com
If www.example.com is hit than nothing should happen
But if I hit www.example.com/events than a get parameter viz. "home" be appended to it. Final URL should be as follows:
www.example.com/events/?home
I want to use this parameter for further processing.
my current .htaccess file contains following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteRule ^landing-page=([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and i m working on wordpress project.
Try this:
RewriteCond !^/$
RewriteRule ^/(.*)$ /$1?home
Depending on your hosting environment the URL may or may not start with a slash, so you might have to remove it from the RewriteRule.

Htaccess redirect with cakePHP

I have a cakePHP app working at http://domain1.com/domain2, and want to point http://domain2.com/ to this application.
I have done this change the document root of domain2 to public_html/domain2, but, when I go to: domain2.com all css, javascript and images are not loaded, with a message saying controller not found.
What I can do?
All domains have a folder with their domains without the TLD at domain1.com, I think if I create a htaccess and get the domain without TLD, and finally change rewriteBase, will work as expected, but don't know how to do this.
Current htaccess of domain2:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
You can try adding an htaccess file in domain2's document root with the following rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.(css|js|png|jpe?g|gif|bmp|ico)$ [NC]
RewriteRule ^/?domain2/(.*) /$1 [L,PT]
This should remove the domain2 part of the links.

Resources