.htaccess redirect to subdirectory - regex

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]

Related

Apache and mod_rewrite: Point any domain to any directory

I've been working with my .htaccess file and mod_rewrite for a couple of days now trying to create a rule that allows people to point their own domains to paths of my website.
i.e. they have created a landing page on my website, located at www.website.com/landingPages/myUniqueWebsite
and they would like to point their domain, www.myuniquewebsite.com to that url above.
Could anyone suggest what apache rule to use to accomplish this?
My .htaccess currently looks like this:
# disallow access to any directories without an index file
Options -Indexes
RewriteEngine on
# remove trailing slash
RewriteRule ^(.*)/$ /myProject/$1 [L,R=301]
FallbackResource ../appContent/BasePage.php
Where the BasePage above takes the directory data from the URL and gets the users landing page data from the db.
Also should they be using domain pointing or aliasing in their hosting provider dashboard?

.htaccess and subdirectories

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

.htaccess redirect root to folder

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]

Display Folder Contents External of CFWheels Influence

My host provider has CFWheels set up as the root www folder I can access. However, I am trying to add a folder that is independent of the framework. In folder foo/ I added a blank application.cfc as told here in the folder. But, when I upload the folder and try to view it on mywebsite.com/foo I get
Could not find the view page for the index action in the Admin controller.
Could the host have disabled my ability to do this? I also read that you can place files you don't want CFWheels to affect by adding them to miscellaneous/ but want to avoid that if possible.
Two things to check:
1) Have you excluded 'foo' in any URL rewriting files - i.e, .htaccess (apache etc) or web.config (IIS etc)? If you add it there it will bypass wheels easily.
i.e:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/(foo|flex2gateway|jrunscripts|cfide|cfformgateway|CFFileServlet|cffileservlet|railo-context|files|images|javascripts|miscellaneous|stylesheets|robots.txt|favicon.ico|sitemap.xml|rewrite.cfm)($|/.*$) [NC]
RewriteRule ^(.*)$ ./rewrite.cfm/$1 [NS,L]
2) If you're not using url rewriting, then it might be there's a catchall route in your config/routes.cfm file.
Do you have anything with a wildcard there?
i.e
addRoute(name="catchall", pattern="*", controller="admin", action="index");
Try putting some content in your /foo/Application.cfc file.
component {
this.name = "foo";
}
Also, make sure the file name starts with a capital "A" - case matters on Unix/Linux servers.

Redirecting home to page in subdirectory, mask url

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.