I have two independend websites on my server. Of which one website is located in a subfolder of the other. Both websites are accessible over two different domains. Following the folder structure on my server:
/www <- one.com
/index.html
/assets
...
/folder <- two.com
/.htaccess
/index.html
/assets
...
Therefore, if I want to access website two I can do so with the following URLs:
one.com/folder
two.com
My problem: Using absolute paths to include files (css/js/img) in website two, I need to adapt my root depending over which URL the user access website two. Following an example for illustration:
The html file /www/folder/index.html contains an image:
<img src="/assets/img.jpg" />
If the user access this html file via the domain one.com/folder/index.html the image source path gets translated to one.com/assets/img.jpg where it won't find any image. Correct would have been one.com/folder/assets/img.jpg (one notice the folder in the path). Obviously, if the user calls two.com/index.html the problem doesn't exist.
Therefore, I thought I would change the root (base directory) of website two via .htaccess mod rewrite depending on which URL gets called. Following the simple pseudo code I would like to implement:
if url == one.com/folder*
root = /folder/
else
root = /
And following what I got so far for my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?one\.com
RewriteRule ^/(.*)$ /folder/$1 [R]
Unfortunately, it seems as if I am missing something here. So far it doesn't work. Any advice is much appreciated!
You can place this rule in /www/.htaccess folder:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(assets/.+)$ /folder/$1 [L,NC,R=301]
Related
I am trying to make a .htaccess file that is basically a wildcard setup. I have a folder structure as below.
public_html/sites is the root directory and in this folder there are two sub directories:
public_html/sites/brand (there are many brand folders, just used brand as example)
public_html/sites/brand/event (there are many events in a brand folder, just used event as example)
I have files in each event folder such as index.php and media.php
I have been unsuccessful in rewriting the media page to the URL structure I am looking for. Below is my current .htaccess file.
RewriteEngine On
RewriteRule ^media/([^/]*)$ /media.php?unqid=$1 [L]
So the expected URL I am wanting is /testbrand/4177/media/123456. I will have serveral brands and several events under each brand so I am needing some sort of wildcard if possible. Any help is appreciated. Thanks in advance.
If you are wanting to have a URL like this
http://example.com/testbrand/4177/media/123456
And your brands are dynamic, then your rewrite should probably look something like this.
RewriteRule ^(?:[^/]+)/(?:[0-9]+)/media/([0-9]+)/?$ /media.php?unqid=$1 [L]
Based on your current internal URL you'll only be sending the id number that comes after /media/ to PHP. If you have more info you need to send, then you need to update your internal URI parameters.
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteRule ^([^/]+/[^/]+)/media/(\d+)/?$ $1/media.php?unqid=$2 [L,NC,QSA]
This will load /testbrand/4177/media.php?unqid=123456 when you request /testbrand/4177/media/123456
I'm trying to make URL's look better by using a RewriteRule in .htaccess, but it doesn't work.
This is the case. I have a root folder in which there is a PHP-file called pdf.php. The script in that file sends a PDF-file to the user, which name is given as a variable in the URL. The PDF-files are in a folder called pdf, placed in the root. That folder is protected so that it's only possible to get a PDF-file by using the script. All that for security reasons.
You can download the PDF-files when you go to http://example.com/pdf.php?file=pdf/File.pdf for instance, where pdf/File.pdf is the path to the PDF-file. That's working fine. I want it to work when you simply go to http://example.com/pdf/File.pdf, so that URL has to be rewritten to the one mentioned before.
I tried to make a RewriteRule using a generator, but it doesn't work.
The following rules are in the .htaccess-file in the folder pdf. Placing it in the root didn't work either.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^pdf/([^/]*)$ /pdf.php?file=pdf/$1
The protection of the folder pdf is as follows.
ErrorDocument 403 http://example.com/
Order deny,allow
Deny from all
Try this code in root .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# to convert spaces to hyphens
RewriteRule "^(pdf)/(\S*) +(.*)$" /$1/$2-$3 [L,NE,R=302]
RewriteRule ^(pdf/.+)$ /pdf.php?file=$1 [L,QSA,B,NC]
Let's say I have a domain called test.com.
Now my index.html is situated in /public_html/client/frontend/questionnaire/index.html, so I can access it in my browser via http://test.com/client/frontend/questionnaire/index.html.
What I want to achieve is:
* As soon as a user enters the url http://test.com, he or she should directly access the index.html
* Restrict the user so that he can only access this index.html file and not other directories on the server.
I think it should work somehow with the correct .htaccess configuration.
Any help would be great :)
You can use this code in your DOCUMENT_ROOT/.htaccess file:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^$ client/frontend/questionnaire/index.html [L]
Here Options -Indexes is used to disable directory listing.
We have our company websites and in that we have careers tab . All files of our company website are placed into a root folder.So for different career openings we created different pages which are being placed inside the root folder for e.g http:/mycompany.com/androidDeveloper.php.But now we want url to look differently i.e .When androidDeveloper.php is openned in Url I want it to be seen as http:/mycompany.com/Careers/androidDeveloper.php but I don't want to create new directory as mycompany.com/careers in my root directory is there any way where in above mentioned can be possible
I tried doing this in .htaccess file but doesn't seems to work
Redirect http://mycompany.com/androidDeveloper.php http://mycompany.com/careers/androidDeveloper.php
You can try this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^careers(/.*)?$ $1 [L,NC]
I'm using wordpress.
I'd like my site's domain root to display contents of another page while still showing my domain root as the url.
EXAMPLE: "http://www.mysite.com" displays contents of "http://www.mysite.com/blogs/home"
but users still see "http://www.mysite.com" in the address bar.
I've managed to get the redirect working, but it's not masking the URL. It essentially is redirecting.
Here's what I have now in my htaccess:
RewriteEngine on
RewriteRule ^\/?$ \/blogs\/home\/ [R,NC]
The R option forces an external redirect. Try just [NC] instead
what about this way.
put the index.php and .htaccess file in the root of your domain.
edit index.php to grab the "wp-blog-header.php" file from what ever location you put it. For example, if your wordpress file is located in blogs/home/ sub directory, you change the index.php file located in the root directory as require('./blogs/home/wp-blog-header.php').
forget about the redirect issue.
I think this is the easiest way. Or did I misunderstand your question?
There is a very simple solutions to this problem. In fact wordpress has an option to accomplish this task.
Go to Dashboard->Settings->Reading->Front page displays
Select a static page as front page.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^$ /blogs/home [NC,P]
PS: Make sure you have mod_proxy enabled in your Apache config.