Redirecting */test/* in httpd.conf to */* [Removing /test/ in path] - url-rewriting

we've been running a test verions of our site at www.mystie.com/test/ and these urls are being used by everyday people... how can i configure httpd.conf to now redirect all these old urls to the / location?
ie,
www.mysite.com/test/image1.jpg
should be:
www.mysite.com/image1.jpg
There are other httpd conf rules in there, so i assume i 'll have to place this up front

Just add these lines:
RewriteEngine on
RewriteBase /
RewriteRule ^test/(.*)$ /$1 [R=301,NC,L]
If lines 1 and 2 have already been set, then you can omit those.
If you prefer, you can add this into your .htaccess file in the root web directory instead. Slightly slower, but saves restarting httpd.

I guess you would need a 301 redirect (which should help in SEO as well)
Redirect 301 /test/ /

Looks like #melkamo has the .htaccess covered.
The alias_module will allow you to do it in httpd.conf
`Redirect permanent /test http://localhost`
It will erase test from the URL if it is the first subdirectory

Related

.htaccess redirect to subdirectory for Ruby application deployed by passenger

My Ruby on Rails project is on justhost server. When I am creating there ruby project, it is creating this in folder rails_apps by default.
For my project, I have created symlinks.
ln -s ~/rails_apps/webworth/public ~/public_html/webworth
And
ln -s ~/rails_apps/webworth ~/public_html/webworth_app [Purpose of this symlink just for browsing files by ftp client]
I created .htaccess file in ~/rails_apps/webworth/public directory. Below is the .htaccess code
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv development
RailsBaseURI /webworth
SetEnv GEM_HOME /home5/worthgur/ruby/gems
and one .htaccess file in ~/public_html. Below is the code:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine on
Options +SymLinksIfOwnerMatch
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?webworth.com [NC]
RewriteCond %{REQUEST_URI} !webworth/ [NC]
RewriteRule ^(.*)$ "webworth\/$1" [L]
Everything is working proper with these structure of .htaccess files except one problem. Extra text is appending to all urls in my project i.e "webworth" for all links generated by routes.rb file. And I want to remove this extra text "webworth" from all URL's.
Now urls are generating for example in this manner.
http://webworth.com/webworth/tags/smartphones
while it should be http://webworth.com/tags/smartphones.
This extra text i.e "webworth" was added previously for the folder that has to be accessed since it was not in the document root for the site and because of this extra text, extra text is appending to all URL's generated by routes.rb file thru ~/rails_apps/webworth/public/.htaccess file [Reason: RailsBaseURI /webworth]
I guess this can be fixed by changing RailsBaseURI /webworth to RailsBaseURI / in ~/rails_apps/webworth/public/.htaccess file.
I did that and I am sure I could not write proper commands in ~/public_html/.htaccess file so that I can redirect the traffic from the public_html to the symlink (webworth) for my site. I used many options but couldn't figure out how it will work. Please help to write ~/public_html/.htaccess file properly to redirect the traffic from public_html folder to my symlink(webworth).
Justhost suggested this link: How to host the Primary Domain from a subfolder. But still I could not figure out the issue. Thanks
I had the same problem with justhost and I solved it without adding any redirect.
I set my rails app public folder to be the main site public folder.
I renamed the original "public_html" to "public_html_backup", just in case.
Added a symlink ln -s ~/myRailsApp/public ~/public_html
in my htaccess I changed RailsBaseURI /myRailsApp to RailsBaseURI /, resulting in:
<IfModule mod_passenger.c>
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv production
RackBaseURI /
SetEnv GEM_HOME /yourUserPath.../ruby/gems
</IfModule>
I hope this can help you.
Cheers

Mod Rewrite Rule redirects

I was trying to password protect a folder on our server. However, each time I included .htaccess to that folder, and .htpasswd, it was automatically redirecting everyone to a 401 page without any login prompt.
When i visited my root directly, i saw this .htaccess:
RewriteBase /
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^www\.(.+)
#RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
#RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
I commented it out and my .htpasswd & .htaccess to the foldr works, however, as my mod rewrite isn't the best, I wasn't sure if commenting the above will create problems for my website?
thanks.
This is basically just redirecting any www.host.ext to host.ext, and returns a 301 Moved Permanently response code.
If you don't care about that functionality you should be able to comment it out.
post your subdirectories htaccess file and we can see if we can sort your original issue out.

Using mod_rewrite to redirect all pages in folder on old domain to index of new domain

I'm trying to redirect all pages on an old site (wellnowwhat.net/nin/*.*) to the index of a new site (sykonaut.net/nin_old/). I only have access to the new site's .htaccess (the old site is owned by a friend), so I'm testing going the opposite direction. I can redirect the root (sykonaut.net) to his root (wellnowwhat.net) using mod_rewrite, but I cannot redirect my nin_old directory to his nin directory. I'm guessing I wouldn't be able to redirect the opposite direction, either. Here is [the entirety of] the code in my .htaccess:
AddHandler php5_2-wrap .php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.sykonaut.net$ [NC]
RewriteRule ^/nin_old(.*)$ http://www.wellnowwhat.net/nin [R,NC,L]
It does not work. Anyone know why?
Place your .htaccess in the nin_old directory.
RewriteEngine on
RewriteBase /nin_old
RewriteRule ^.* http://www.wellnowwhat.net/nin/ [R,NC,L]
When you redirect to an external URL to a directory, I would add the trailing slash as this reduce an extra redirection.
Also when you test everything and it's all right, change R to R=301 as this is preferred by most search engine for Permanent Redirection.
In apache 2.0 and higher, the prefix (leading "/") is removed from the URI before it's put through the rewrite engine for rules in the .htaccess file. Try removing the leading slash from your regular expression in your rule:
RewriteRule ^nin_old(.*)$ http://www.wellnowwhat.net/nin [R,NC,L]

htaccess rewrite for clean image url

I'm looking for a re-write for an identicon generator where something like
images/1-2.png
Would be interpretted on the server as
images/index.php?one=1&two=2
But it would still show site.com/images/1-2.png in the address bar.
Assumed there's only one dash (-) in the file name
Doable?
This will do it, put this in your .htaccess file in the root of your application.
RewriteEngine on
RewriteBase /
RewriteRule ^images/(\d)-(\d)\.png images/index.php?one=$1&two=$2 [NC,L]

Ko3 - URL Rewriting problem - Removing index.php

I'm developing a website using Kohana 3 (1rst time I use a framework). Locally, everything works perfectly. At the moment, I have a default template controller, a multi-language support and my 'index.php' is correctly removed. So before going further, I tested if it worked on my server and I got an endless loop.
I followed the tutorial from the unofficial wiki for the multi-language implementation: http://www.kerkness.ca/wiki/doku.php?id=example_of_a_multi-language_website
A redirection to the default language occurs if the language is not specified in the uri so I figured the problem might have come from there even though it worked locally, so I removed it to see what happens without the redirection. Now, I can see my home page, but whatever the uri is in the web browser, the home page will always be called. I inserted the following line in my home view to check what the uri was:
request::instance()->uri() and effectively, the uri is always: /en/home/
I put the index.php back (in the bootstrap) and everything worked fine again, even with the redirection to the default language.
My first guess was that the uri isn't rewritten correctly, so I tried to change the .htaccess but no success...
Here's my .htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /dev/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
(btw I also tried the other RewriteRule in the unofficial wiki, doesn't work either)
Additional info:
Host: WebHostingPad
Apache: v2.2.11
PHP: 5.2.9
Rewrite_Module is activated
Thank you, I would really appreciate your help because I've been trying to fix this for days now and it's really starting to annoy me ;)
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
So the Kohana::init looks like this;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
If it worked with the original .htaccess, there's no need to change it at all.
The problem came from $_SERVER['PATH_INFO'] which returned no value...
This issue can be solved by adding the following line to the php.ini:
cgi.fix_pathinfo=0

Resources