i have 2 folder a and b
I want to rewrite url as like subdomain style.
domain.com/a => a.domain.com => it will run folder a
domain.com/b => b.domain.com => it will run folder b
Thanks in advance
Assuming the folders a and b are at the root of your domain, try adding this to the .htaccess file in your web document root folder (often public_html or htdocs):
Options -Multiviews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([ab])\.domain\.com [NC]
RewriteRule ^ %1%{REQUEST_URI} [L]
This assumes that mod_rewrite is both installed and activated for .htaccess files.
If you are not sure, to check if mod_rewrite is even installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for .htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All
Related
In my /public_html/ I have installed an WordPress site. Now I have installed an laravel application inside /public_html/app/.
Then in /public_html/app/.htaccess I have added:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
In /public_html/app/public/.htaccess I have added:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /app/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
When I trying to open https://example.com/app/ I've got error 404. When I try to open directly https://example.com/app/public I've got half working site because it is searching for the css/images in https://example.com/.
What is need to be changed in the htaccesss in order to work.
The goal is to have a button on the main WP site and when I click it to load the laravel site.
RewriteBase /app/
You need to remove the RewriteBase directive. This ends up rewriting the request to /app/index.php, when it should be /app/public/index.php. The default is to rewrite to the current directory (the directory that contains the .htaccess file), so the RewriteBase directive is not required here.
(Or, you could set this "correctly" to RewriteBase /app/public - but that is not necessary and would then hardcode this installation to the /app directory.)
I've got half working site because it is searching for the css/images in https://example.com/
It depends on where your images are. If images are located at /app/public/assets/images/myimage.jpg then you should be referencing your images using a root-relative URL (starting with a slash), excluding the public directory, eg. href="/app/assets/images/myimage.jpg".
UPDATE:
is this means that I now have to manually edit all images, links, buttons, etc on the site in order to add /app/... in front of the assets?
Ordinarily, yes. In the same way you have presumably added /app/ before all your internal links to your pages. (?)
Logo for example - <img src="/assets/main/img/logo.png">
However, since you are using a root-relative URL and your Laravel assets are in a known location, then you could workaround this by implementing a rewrite in the root (WordPress) .htaccess file to rewrite your Laravel assets to the correct location (presumably /app/public/...).
However, this does mean that you cannot then have an /assets subdirectory in the root (without implementing additional filesystem checks), nor have a WordPress URL that starts /assets, since it will conflict and won't be accessible.
For example, at the top of the /.htaccess file, before any other WordPress directives you could do something like the following:
# Rewrite Laravel assets to the correct location
RewriteRule ^assets/.+ app/public/$0 [L]
# BEGIN WordPress
:
Where $0 is a backreference that contains the entire URL-path that is matched by the RewriteRule pattern.
Now, any request for /assets/<something> will be internally rewritten to /app/public/assets/<something>. /assets/ itself won't be rewritten.
I feel like I have no idea what I'm doing.
My CodeIngiter application is working fine in WAMP using this URL: http://localhost/myapp.
However, when I moved it to my AWS EC2 micro instance Amazon Linux AMI /var/www/html/myapp and tried to access my application using this URL, http://xxx-xxx-xxx-xxx-xxx.compute-1.amazonaws.com/myapp, all I get is a blank white page.
Here is everything I tried:
1. Disabled "Index of" display
cd /etc/httpd/conf/
sudo nano httpd.conf
Options -Indexes FollowSymLinks
2. Turned on Error reporting in php.ini
error_reporting = E_ALL | E_STRICT
display_errors = On
3. Development Environment
In the index.php (root of my applicaiton),
define('ENVIRONMENT', 'development');
4. Restarted Apache
cd /etc/init.d
sudo httpd -k restart
5. DocumentRoot
DocumentRoot "/var/www/html/"
Also tried:
DocumentRoot "/var/www/html"
DocumentRoot "/var/www/html/myapp"
6. echo test from index.php
I printed a test message from both my index.php
(root of my app), as well as my controller. Both
worked. I don't understand why my view is not being
displayed.
<?php echo "test"; ...
//This worked.
7. Replaced www/html/myapp with www/html/
I moved the contents of my application outside of "myapp"
folder into www/html directory.
Also, DocumentRoot "/var/www/html/".
Also, my .htaccess file (in root of myapp)
is "RewriteBase /" (see point 8 below).
Also, I removed .htaccess from /var/www/html/
but same blank page.
8. .htaccess
The following .htaccess file is located in the root
of my CodeIgniter application. I also tried changing
RewriteBase /myapp to RewriteBase / but I'm still
getting this blank page with no errors.
RewriteEngine On
# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/
RewriteBase /myapp
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
I do not know what to try again.
I am currently having an issue using the URL manager and/or the apache mod_rewrite or maybe something else entirely.
With showScriptName set to false, navigating to addresses such as domain.com/login, domain.com/logout, domain.com/site/login are all behaving the same way. It simply shows the main site/index, as if I were to navigate to domain.com/eeofjew9j8jfdedfmewf (jibberish).
Maybe it's an issue with my Yii settings? Here are those (sorry for the sloppiness):
'components'=>array(
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'login'=>'site/login',
'logout'=>'site/logout',
'register'=>'users/register'
),
,...
Here is how I have my .htaccess setup in the www root:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
I am using a VPS server, so I have root access to make any changes needed to apache. I've checked my phpinfo and mod_rewrite is running and enabled. In my apache config, I have for my www directory:
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
I've been scratching my head on this issue through 3 different hosts (godaddy, dreamhost, and lithiumhosting) so I'm assuming it's an issue on my end with this. Now that I have a VPS though, I'm hoping I can finally figure out my issue and solve it.
First verify that the server is parsing the .htaccess file. This is simply done by placing random text in the .htaccess file such as
CREATE AN ERROR
If this gives you a server error then the file is being parsed. You may have to move the .htaccess file up a directory to get this to work.
After this is working check to make sure the rewrite module in Apache is on. First check phpinfo and look for the running module. If not you may have to delete the comment (#) character in front of the module.
After the module shows up in phpinfo then see if you can do a basic rewrite to make sure that there are not problems with Apache.
RewriteEngine on
RewriteRule ^ http://google.com/? [L,R]
If that is not working try adding the
Options +SymLinksIfOwnerMatch
to the file
Once you have Apache doing it's part now it is up to yii. This code:
RewriteEngine On
RewriteBase /mybasedirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
adds the rewrite base option which may be necessary if you do not have the files in the document root such as htdocs
finally if that does not solve the problem then limit your rule to a simple rule such as
'contact'=>'site/contact',
and see if at least redirects to where you think it should. Of course you may have to check the basic rules of .htaccess again to make sure that overide is allowed and there isn't an errant .htaccess in a subdirectory. I hope that helps. I finally got mine working.
What happens if you delete these lines!
enter code here
# otherwise forward it to index.php
RewriteRule . index.php
if you add this code see if it works
'<action:(login|logout|register|contact)>' => 'site/<action>',
I've just created a new website and am ready to switch from an my current webserver to a new webserver.
The current webserver will be renamed www2
The new webserver will be known as www
I want to redirect all traffic from www2 to www except for one directory. My directory structure looks like this:
/var
/www
/html
index.html
page2.html
/orange
index.html
...
/archive
index.html
important-page1.html
important-page2.html
/turquoise
index.html
...
I would like to redirect everything to the equivalent www page
e.g. www2.mydomain.com/orange/index.html -> www.mydomain.com/orange/index.html
www2.mydomain.com/turquoise/index.html -> www.mydomain.com/turquoise/index.html
EXCEPT for the /archive folder. I would like users requesting :
www2.mydomain.com/archive/important-page1.html to view the page on www2 and not be redirected.
Do I use mod_rewrite or mod_redirect? And can I set this up in httpd.conf?
Thanks
Yes, you would need mod_rewrite.
Try:
RewriteEngine on
RewriteCond $1 !^archive
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
Note: The 301 in R=301 is a permanent redirect, you'll need to change it to 302 if you want it to be temporary.
Within the VirtualHost config in httpd.conf (or httpd.conf.d file) for www2.mydomain.com add:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/archive.*
RewriteRule ^(.*)$ http://www.mydomain.com$1
I am building a web app that puts out a link like the following:
http://www.sample.com/?a=bj7phm
I would like for it to look something like this:
http://www.sample.com/BJ7PHM
Is this possible within the HTACCESS?
-B
In order to do URL rewriting, you first need to:
Make sure you have mod_rewrite enabled on your server.
Make sure you have the proper permissions to add rules to your .htaccess file.
(AllowOverride must be set to All or include FileInfo)
Then create the following .htaccess file in your web root:
RewriteEngine On
RewriteRule ^([\-_0-9A-Za-z]+)$ index.php?a=$1 [L]
You can customize RewriteRule as much as you want.
The first parameter is the regular expression to match the REQUEST_URI with (relative to the folder the .htaccess is in).
The second parameter is what you want to rewrite it to, $n being your match groups.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9a-zA-Z+]{1,7})$?a=$1 [L]
</IfModule>