I have a domain example.com and mainexample.com- i want a example.com to point to mainexample.com/social/pre/register/121 which already driven by the htaccess file.
I am not sure how to go about this.. I have pointed the two domains at the same directory. I'm on a virtual shared server so I am using directadmin with php/codeigniter.
The site uses the standard htaccess file for codeigniter listed below
RewriteEngine On
RewriteBase /upd8r_jul
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
You're going to want to add slashes to the %{REQUEST_URI} lines, because they all look like /something and not something like the URI's used against matches in RewriteRule's. But that does affect the question you're asking.
If you want to redirect http://example.com/ to http://mainexample.com/social/pre/register/121 then add these rules above the rules you already have in your htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^$ http://mainexample.com/social/pre/register/121 [L,R=301]
Related
I have a wordpress website physically located in the "wordpress" subfolder of the root folder of the website. I manage to hide the subfolder "wordpress" in the URL with the following code:
.htaccess on root folder
RewriteEngine On
RewriteBase /
RewriteRule ^$ wordpress/ [L]
RewriteRule ^(.*)$ wordpress/$1 [L]
.htaccess in wordpress subfolder
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
However, I have another website in another subfolder let's call it "other-wp" and this needs to remain as it is, with the URL pointing to:
https://mywebsite.com/other-wp/
Since I managed to hide the "wordpress" folder in the URL, I am unable to acces my "other-wp" it says the page doesn't exist.
I'm not skilled with coding for .htaccess so i don't know what i need to do to fix it.
Could you help?
You need to implement an exception for that second resource:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/other-wp
RewriteRule ^/?(.*)$ /wordpress/$1 [L]
I also made some other modifications to that top level configuration file, just smaller optimizations. In general you should check if you can place such global rules in the actual http server's host configuration. Using distributed configuration files (".htaccess") is just a fallback if you have no access to the real configuration. They work, but come with disadvantages.
i created a new folder like /var/websites/menora.sichermove.co.in, and staged all files to the directory , now i am getting 'Internal Server Error' please help me to create a new htaccess file for sub domain?
Simply open a new file in Notepade++ and copy the following code in it and, upload in the director where u want by using file zilla.. and let me know when you done it..
thanks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
RewriteCond $1 !^(index\.php|admin|dotproject|images|fonts|js|css|.htpasswd|robots\.txt)
I've been working on a codeigniter application. When I first started developing it I used the following url structure:
http://somewebsite.com/application/login/
I changed the site to run over https
https://www.somewebsite.com/application/login/
The problem is any calls to the server only work like this.
https://www.somewebsite.com/application/index.php/login/
I want to get rid of the index.php. Any thoughts?
You need to have you .htaccess rewrite SSL properly. This is an .htaccess I use that works - although it FORCES SSL. Not sure if you want to do that:
<IfModule mod_rewrite.c>
RewriteEngine On
#Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
check and edit the application/config/config.php.
in that change the following line
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
just remove index.php and then it should work lust fine...
I have been looking all over and I can't find a solution that works for me.
I'm trying to redirect http://example.com/files/file.ext -> http://example.com/users/documents/file.ext
No matter what I try when I got directly to the file it downloads it. The GET request for the file doesn't show in any of my apache logs either. I have logging on debug.
[Edit]
The files I'm trying to download are of various types including ppt, pdf, xls, zip, doc, etc. I want to rewrite the filename to the end of the new URI. I am also using CodeIgniter so /users/documents/ is a RESTy uri.
Anyone have a fix?
Here is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
<IfModule mod_php5.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [N]
RewriteCond %{REQUEST_URI} ^/files/ [NC]
RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
If this is in your htaccess file, try replacing this line:
RewriteRule ^/files/(.*)$ /users/documents/$1 [L,R=301]
with:
RewriteRule ^/?files/(.*)$ /users/documents/$1 [L,R=301]
And putting the condition and rule before any of the index.php routing rules.
I went to http://martinmelin.se/rewrite-rule-tester/ and tested my rewrite rules.
It said the RewriteCond wasn't matching anything, but when I remove the rule it matches.
Working Rule:
RewriteRule ^/?files/(.*)$ /users/documents/$1 [L,R=301]
Moving this to the top of the htaccess file fixes the issue.
I have the htaccess rules below that work almost perfectly. When I load
http://localhost:8888/site/name/register/ it redirects to http://localhost:8888/site/name/fr/register/ as is intended.
But when I load http://localhost:8888/site/name/register (sans trailing slash) the redirect does not occur. I'm sure I just need to add a slash somewhere in the .htaccess rules but can not find where (adding it to the RewriteBase makes no difference).
RewriteEngine On
RewriteBase /site/name/
#some URI processing also occurs in routing.php!
RewriteCond $1 !^(fr|nl)$
#don't apply the rule to the assets folders
RewriteCond $1 !^css$
RewriteCond $1 !^js$
RewriteRule ^([^/]+)/.* /site/name/fr/$0 [L,R=301]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Note the site homepage is http://localhost:8888/site/name
How can I get the redirect to occur also at http://localhost:8888/site/name/register ?
^([^/]+)/.* means everything that comes before the first slash. In other words, a slash is required. If you just remove the slash it should work.
RewriteRule ^([^/]+).* /site/name/fr/$0 [L,R=301]