LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-04-2013, 10:01 PM   #1
NetEng1
Member
 
Registered: Aug 2011
Distribution: ubuntu
Posts: 40

Rep: Reputation: Disabled
Apache redirect of non existent subdirectories


We are running apache2 v2.2.22 on openSuSE 12.2. We have one website defined with the files at /srv/www/htdocs. This is replacing an older version that we had in place for alpha testing. With the old system, users had to enter in the directory (ie. www.mydomain.com/startlocation) where the index file is.

On the new server, we just want them to enter in www.mydomain.com without the subdirectory. However, for the team that tested the old system, we would like that the old url with the subdirectory would still work for them. This way if someone entered in www.mydomain.com/startlocation, it would get redirected to www.mydomain.com. I have been asked to allow anything after the domain name and redirect it to the root.

After some research, I decided to try out mod_rewrite. In some searches on its use, the following lines should be added to .htaccess under the root directory. I created the file and entered in the following as its contents:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ http://www.mydomain.com/=$1 [R=301,L]

I restarted apache2, but it did not work. I ensured that mod_rewrite was installed by using the apache2ctl -M command.

What am I missing?

Thanks in advanced
 
Old 03-05-2013, 02:24 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
You're missing some sanity! Don't do this!

If a page doesn't exist, the server should 404. If you want to redirect *SPECIFIC* locations, then that's fine, but not EVERYTHING. your method says that ever image or other file that doesn't exist is going to be pushed to the default site. Every malicious system out there will get a positive response to every single opportunistic scan instead of a dead end 404.

so redirect on /startlocation and any other select ones if need bee, no problem at all with that, but don't do it on a blanket rule.
 
Old 03-05-2013, 02:25 AM   #3
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
On the new server, we just want them to enter in www.mydomain.com without the subdirectory. However, for the team that tested the old system, we would like that the old url with the subdirectory would still work for them. This way if someone entered in www.mydomain.com/startlocation, it would get redirected to www.mydomain.com. I have been asked to allow anything after the domain name and redirect it to the root.
Huh, I don't get what exactly you're trying to do.
If you want http://www.mydomain.com/startlocation been redirected to http://www.mydomain.com/, you need just:
Code:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/startlocation
RewriteRule startlocation(.*)$ / [R=301,L]
Since you're going to put the rewrite stuff in a .htaccess file, you should also make sure that you have in httpd.conf:
Code:
AllowOverride All
so apache takes care of the .htaccess files

Regards
 
Old 03-05-2013, 02:29 AM   #4
stormpunk
LQ Newbie
 
Registered: Mar 2004
Distribution: windows 7
Posts: 21

Rep: Reputation: 2
Unless I'm missing something which I could be then I would just use the alias module. One line and done
Code:
Redirect permanent /startlocation http://www.example.com
 
Old 03-05-2013, 05:37 AM   #5
NetEng1
Member
 
Registered: Aug 2011
Distribution: ubuntu
Posts: 40

Original Poster
Rep: Reputation: Disabled
Thank you all for your responses. Chris, you make an very valid point. I will try to talk my manager out of this. I was not keen on doing it in the first place.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.htaccess redirect non-existent directory to subdomain PlymWS Linux - Server 2 03-12-2011 11:19 AM
Apache mod_rewrite Subdirectories and IP question mgichoga Linux - Server 0 08-12-2009 08:42 AM
apache behavior on non-existent virtual hosts zovres Linux - Server 2 05-26-2009 05:29 PM
Apache? Php? non-existent pages getting served... bulliver Linux - General 2 08-14-2006 07:48 PM
Hosting and using SubDirectories in Apache apocolipse Slackware 1 12-21-2003 10:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration