Forum Moderators: phranque

Message Too Old, No Replies

Trying to hide the real URL in the bar (internal rewrite silently)

         

syrinx

12:32 pm on Mar 20, 2011 (gmt 0)

10+ Year Member



Hello,

I'm trying to convert the URLs with .htaccess to hide the real URL. It's a Simple Machine forum. The forum is using only https but it's not the problem today.

Every URL of the forum should be converted like that:
hxxps:www.domaine.info/forum/SMF1113/index.php ==> hxxps:www.domaine.info/index.php

as examples:
hxxps:www.domaine.info/forum/SMF1113/index.php?board=24.0 ==> hxxps:www.domaine.info/index.php?board=24.0
hxxps:www.domaine.info/forum/SMF1113/index.php?action=profile ==> hxxps:www.domaine.info/index.php?action=profile

I used the following htaccess which is running well. The simplified URLs are working well.
But in the URL's bar, I can still see the real URL. I want to see the simplified URLs!


RewriteEngine on
Options +SymLinksIfOwnerMatch

#obligation to use https
SSLOptions +StrictRequire
SSLRequireSSL
ErrorDocument 403 /err_redirect.php
AuthName "public"
AuthUserFile "/home/domaine/.htpasswds/public_html/passwd"
AuthType Basic
require valid-user
<Files /err_redirect.php>
AuthType none
</Files>

RewriteCond %{HTTP_HOST} ^www\.domaine\.info$
RewriteRule ^(index\.php*)?$ /forum/SMF1113/index.php [L]



How can do to rewrite silently this? To not see the real URL in the URL's bar?

Thank you for help.

g1smd

5:30 pm on Mar 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



URLs are defined in links. Link to the URL you want users to "see" and "use". Change the links on your pages.

Mod_rewrite takes effect after that link is clicked. It is too late to "change" the URL after it has been clicked.

The RewriteRule pattern then matches the incoming URL request and internally converts the filepath the server is going to look in from the default suggested by the URL request, to that suggested by the rule. It changes it so that it internally fetches content from your script filepath.

The final part is to add an external redirect so that if the direct script filepath is externally requested, the server sends a redirect to suggest the browser makes a new request for the new URL. This redirect needs to test THE_REQUEST to be sure this is an external request for the path and not as a result of a previous internal Rewrite.

The basic layout:

# External Redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ^/old-path\ HTTP/
RewriteRule ^old-path http://www.example.com/new-path [R=301,L]


# Internal Rewrite
RewriteRule ^new-path /old-path [L]

g1smd

5:37 pm on Mar 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



https://www.example.info/forum/SMF1113/index.php?action=profile ==> [example.info...] Your proposed "new" URLs are far from optimum. You risk Duplicate Content from
www.example.info/index.php?action=profile
and
www.example.info/?action=profile
for example.

There is no need to expose the
.php
technology in the URLs. Likewise the
action=
part is not required.

I would use
www.example.info/profile
here, and rewrite external requests for
/profile
to internally fetch content from
/index.php?action=profile
.

URLs are a reference system used on the web. You can make your URLs whatever you want. They in no way have to reflect the internal structure of your server.

syrinx

8:42 pm on Mar 21, 2011 (gmt 0)

10+ Year Member



I want to hide the internal structure of the folders. But I understand that with Rewrite I can cheat only the connection in one direction: navigator => web server. But the web server will always answer the real URL. Is it correct?

The only solution is that Simple Machine Forum rewrites itself the URLs. But I don't know a MOD able to do that.

g1smd

9:12 pm on Mar 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you have content inside the server at
/old-file.html
, normal server operation would allow you to access it by requesting
www.example.com/old-file.html
.

Using a Rewrite you can set things so that a request for
www.example.com/new-reference
pulls content from the
/old-file.html
server path without revealing that is where it is coming from.

To avoid both Duplicate Content issues and direct access to the
/old-file.html
location, you add a Redirect. With that external redirect in place, a request for
www.example.com/old-file.html
triggers the server to respond not with content but with a 301 external redirect telling the browser to make a new request for the new URL at
www.example.com/new-reference
instead.

So, the full solution has both a redirect and a rewrite, but with the redirect explicitly triggering only for direct client requests for the old path. For everything to function perfectly, you must link to the exact URL that you want users to "see" and "use". Clicking links within the site must not invoke any sort of external redirect.

jdMorgan

10:58 pm on Mar 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be very clear:

  • URLs are used "out there on the Web."
  • Filepaths are used "here inside the server."
  • The primary job of a Web server is to map client-requested URLs to the internal server filepaths which contain (or can generate) the content requested for the URLs in your domain.
  • Sometimes this mapping is fairly direct, as in (URL) http://example.com/robots.txt --maps to--> (filepath) /htdocs/robots.txt
  • Sometimes the URL-to-server-filepath mapping is not direct, because a module such as Apache mod_rewrite is used to modify it. For example, you might test the client's user-agent string, and map googlebot robots.txt requests to a file called robots_g.txt, while mapping all others to robots_x.txt.
  • As g1smd said, URLs are defined by the links on your pages. These URLs 'exist' whether or not they resolve to any file on any server on the Web.
  • As a Webmaster, you can also define your server's internal file structure almost any way you like.

    Given that you can define any URL you like (as long is it is valid according to the HTTP specifications) and that you can map any URL in your domain to any file inside your server using mod_rewrite, this gives you a lot of flexibility.

    But it is most important to separate the concepts of URLs and filepaths, or everything else will be very confusing...

    Jim
  • syrinx

    5:38 am on Mar 24, 2011 (gmt 0)

    10+ Year Member



    Thank you g1smd and jdMorgan. I think I understand.

    So is there a way to show in the URL's bar this?
    public_html/SMF1113/index.php to be like that [domaine.info...]

    Thanks a lot.

    g1smd

    8:37 am on Mar 24, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    Never show a URL with index.php in it. The correct URL is www.example.com/ with a trailing slash.

    Use an internal rewrite to connect requests for the URL "/" to the server internal filepath at /folder/.

    Use an external redirect for external URL requests for /folder/ and redirect them to "/".

    syrinx

    8:26 pm on Mar 24, 2011 (gmt 0)

    10+ Year Member




    I've tested with this:


    RewriteEngine on

    # External Redirect
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ^/forum/SMF1113\ HTTP/
    RewriteRule ^forum/SMF1113 https://www.domaine.info/ [R=301,L]

    # Internal Rewrite
    RewriteRule ^ /forum/SMF1113 [L]


    It's the same results, I see this in the URL bar: hxxps:www.domaine.info/forum/SMF1113/index.php?board=24.0

    g1smd

    12:53 am on Mar 25, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    The second caret in the RewriteCond should be removed.

    syrinx

    8:54 am on Mar 25, 2011 (gmt 0)

    10+ Year Member



    RewriteEngine on

    # External Redirect
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forum/SMF1113\ HTTP/
    RewriteRule ^forum/SMF1113 https://www.domaine.info/ [R=301,L]

    # Internal Rewrite
    RewriteRule ^ /forum/SMF1113 [L]


    Sorry, still not working.

    g1smd

    9:57 am on Mar 25, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    "Not working" gives no hint as to the "how". Try this:

    # Internal Rewrite
    RewriteCond %{REQUEST_URI} !^/(forum|robots\.txt)
    RewriteRule (.*) /forum/SMF1113/$1 [L]

    syrinx

    4:03 am on Mar 26, 2011 (gmt 0)

    10+ Year Member



    I have always the same thing. I see this in the URL bar: hxxps:www.domaine.info/forum/SMF1113/index.php?board=24.0
    instead of hxxps:www.domaine.info/index.php?board=24.0

    In think, it's the external rewriting which is not working. Because when I go in non SSL mode into the forum, I should switch from https to https with this code RewriteRule ^forum/SMF1113 https://www.domaine.info/ [R=301,L]


    RewriteEngine on

    # External Redirect
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forum/SMF1113\ HTTP/
    RewriteRule ^forum/SMF1113 [domaine.info...] [R=301,L]
    #tested with https and https

    # Internal Rewrite
    RewriteCond %{REQUEST_URI} !^/(forum|robots\.txt)
    RewriteRule (.*) /forum/SMF1113/$1 [L]


    Thanks

    g1smd

    7:31 am on Mar 26, 2011 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



    external rewriting
    There's "external redirecting" and "internal rewriting". Don't confuse the two. Both use a RewriteRule.

    Your condition doesn't allow for attached parameters. Change the pattern slightly.

    # External Redirect index
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forum/SMF1113/(index\.php[^\ ]*)?\ HTTP/
    RewriteRule ^forum/SMF1113 https://www.domaine.info/ [R=301,L]


    # External Redirect other
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /forum/SMF1113[^\ ]*\ HTTP/
    RewriteRule ^forum/SMF1113/(.*) https://www.domaine.info/$1 [R=301,L]


    # Internal Rewrite
    RewriteCond %{REQUEST_URI} !^/(forum|robots\.txt)
    RewriteRule (.*) /forum/SMF1113/$1 [L]

    syrinx

    9:15 am on Mar 26, 2011 (gmt 0)

    10+ Year Member



    Sorry I didn't take care to my words.

    It's not working also, as example, I can read this in the URL bar:
    [domaine.info...]

    syrinx

    3:27 pm on Mar 28, 2011 (gmt 0)

    10+ Year Member



    Do you still have some ideas? Thanks.

    syrinx

    5:41 pm on Apr 5, 2011 (gmt 0)

    10+ Year Member



    Hello, do you have a new idea?