Welcome Guest, Not a member yet? Register   Sign In
Rewrite an URL without 302 redirect
#1

(This post was last modified: 05-16-2015, 08:32 AM by ricoxor.)

I would like to know, how can i rewrite an URL without the 302 redirection.

The website is targeted by 2 domains.

- The first domains `(domain1.com)` focus all the website.
- The second domains `(domain2.com)` focus only one function to do an url shortener

Here is my `.htaccess` : 

Code:
   Options +FollowSymlinks
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.domain2.com$
    RewriteRule ^([A-Za-z0-9-]+)$ http://domain2.com/url/$1 [L]

    Rewritecond %{HTTP_HOST} domain2.com [NC]
    RewriteCond %{REQUEST_URI} ^/$
    Rewriterule ^(.*)$ http://domain2.com/soon/ [QSA,L,R=301]

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

When i call my shothener `http://domain2.com/57b97f2` i'am redirect to `http://domain2.com/url/57b97f2` with a 302 redirection.

How can i avoid this unwanted 302 redirection ?


My controller for the `url()` function is named : `webadmin`

My routes are :

Code:
    $route['default_controller'] = 'webadmin';
    $route['404_override'] = '';
    $route['translate_uri_dashes'] = FALSE;
    $route['(.+)'] = 'webadmin/$1';

 Webadmin controller : 

Code:
   function url($code)
    {
        //do something
    }

EDIT :

I try to use :

Code:
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$
    RewriteRule ^$ /soon [R=302,L]

    RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$
    RewriteRule ^([a-z0-9-]+)$ /url/$1 [NC,N]

But an 404 error is showing...
Reply
#2

On the config.php i have change : $_SERVER['REQUEST_URI'] to $_SERVER['QUERY_STRING'] and now it work.
But i don't know why... Can you explain me ?
Thank's
Reply
#3

It depends on how they setup their server.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB