Redirecting url to different location. use htaccess or main config file

Hi
I am currently working on yii project and has htaccess file in the root as follows


#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://%{HTTP_HOST}



RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
Options +FollowSymLinks
IndexIgnore */*


# 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

the yii project is running under htdocs in apache root in opensuse. I want to run yiiproject.local/bugs from /srv/www/bugzilla

I have done similar stuff in the past but forgot to make notes.

I think I had to do in following steps

  1. modify .htaccess to don’t go to index.php if it is /bugs path.
  2. redirect /bugs to /srv/www/bugzilla

How I can do that ?

Thanks

Hi af!

I’m not sure whether your secure server certificate is for www or non-www but the code would be different than that used by yii (see my signature’s tutorial for my preferred version. Additionally, you don’t need to go through the ^/?(.*)$ nonsense to capture the {REQUEST_URI} variable (which already exists) but that’s just commenting on your “canned code.”

As for your “specification,” you really want to redirect bugs/ first then “escape” srv/www/bugzilla with a RewriteCond just before the redirect all (but file or directory) to index.php.

Before you go through that, though, aren’t you already asking for a file or directory in the srv/www/bugzilla directory? The !-f and !-d exclusions protect those links already.

Then, is srv/www/bugzilla in the same DocumentRoot as your .htaccess? If not, you’ll need to redirect with an (external) absolute redirection, i.e., http://go.somewhere.else.com.

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Then give the above some consideration and, if you still have problems, let me see what you’ve done and I’ll help correct it for you (I don’t code for “script kiddies” so I like to see your attempt - at least I gave you the massive hints as to how/where to add the RewriteRule (to redirect from bugs/) and RewriteCond for bugzilla.).

Regards,

DK

Hi
Thanks for reply.

I went through your tutorial but still can’t see how I can solve my problem.

I think I didn’t explain well in my last post.

Suppose I have www.example.com project running but I want to install bugzilla as well. current project is running from /srv/www/htdocs and bugzilla will be installed in /srv/www/bugzilla.
What is the best way to redirect www.example.com/bugs to /srv/www/bugzilla .

When people visit bugzilla page, whatever is in query string gets appended to www.example.com/bugs
for example when people visit www.example.com/bugs and click on add link the url they see must be like www.example.com/bugs/add

I tried to add

RewriteCond %{REQUEST_URI} =/bugs$
RewriteRule /bugs/(.*) /srv/www/bugzilla/$1 [L]

to www.example.com/.htaccess but it didn’t worked.

I think Alias was designed for situations exactly like this one.

Alias /bugs /srv/www/bugzilla
<Directory /srv/www/bugzilla>
    Require all granted
</Directory>

The only catch is that this will have to go in the main configuration file (httpd.conf) rather than in an htaccess.

Thanks.
Thats what I wanted.

Now I have learnt something about mod_rewrite also.