Forums | Mahara Community

Support /
Clean Profile URL not staying in Browser Bar


Andi Becker's profile picture
Posts: 68

29 June 2021, 1:02

We have changed the User URL to a simple "u" and the profile URL therefore looks like in the image below.

 

Here was the screenshot which demonstrated the Problem but your system don't let me post it as I receive the error:
Sorry, anonymous or newly registered people aren't allowed to post links. Please reword your post to remove any links or URLs and try again.


That is all fine and is also working - B U T - the URL always switches back to the old URL format instead of staying like that in the browser bar and that means that users not easily can type in "resume"  i.e. to get to the resume page because the URL changed back already to the old format which looks pretty ugly and not SEO friendly and it is difficult to read

 

Here was the link demonstrating the problem but again or still I am receiving the error and therefore had to remove the link - I hope you can guess the link and understand what I am talking about - sorry but that is pretty annoying and user-unfriendly such rules !!!

Sorry, anonymous or newly registered people aren't allowed to post links. Please reword your post to remove any links or URLs and try again.

.../view/view?profile=andibecker

much easier would be to have the Clean URL staying in the browser bar and than with /resume you would get to the resume page or any other page you type in its URL path i.e.:

.../u/andibecker/resume 

instead you again end up with: - which is a real headache - especially for students and teachers which are no programmers.

.../view/view?profile=andibecker&page=resume

Is there a way - i.e. via .htaccess - to change the behavior that way that the clean URLs always stay in the browserbar?

Our .htacces looks like follow:

Sorry but getting really upset with those stupid errors in your forum!!!

Sorry, anonymous or newly registered people aren't allowed to post links. Please reword your post to remove any links or URLs and try again.

Could you please REMOVE that blockage so that I can post a SERIOUS PROBLEM which I hope to get solved with the help of community members and they only can solve it If I am also able to post the full .htaccess - the one following is only a Version which does no more reflect the real .htaccess - I had to remove all parts until that stupid error did no more pop up and let me post

You can't copy paste or test that .htaccess on your own system as it is no more complete nor is it anymore functional!

<IfModule mod_rewrite.c>

RewriteEngine on

    # if redirected to url cleaner, redirect to actual lookup file and

# these lines will keep the clean url visible in the browser

RewriteRule ^u/([a-z0-9-]+)/?$ .../user/view.php?profile=$1&%{QUERY_STRING} [L]

RewriteRule ^u/([a-z0-9-]+)/([a-z0-9-]+)/?$ .../view/view.php?profile=$1&page=$2&%{QUERY_STRING} [L]

RewriteRule ^g/([a-z0-9-]+)/?$ .../group/view.php?homepage=$1&%{QUERY_STRING} [L]

RewriteRule ^g/([a-z0-9-]+)/([a-z0-9-]+)/?$ .../view/view.php?homepage=$1&page=$2&%{QUERY_STRING} [L]

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]

RewriteRule ^ %1 [R,L]         

    # do not do anything if already existing file, symbolic link or directory   

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ $1.php [L] 

 </IfModule>


Thanks


P.S,. EVERYWHERE where you might find .../ you have to replace that with the following but without gaps (empty spaces in between.
https : // montessori . contact 
and for the image which is missing you have to check the attachment.

  • Screen Shot 2021-06-28 at 19.33.37.png
Andi Becker's profile picture
Posts: 68

29 June 2021, 20:16

https:/ /montessori.contact/view/blocks.php?id=8&c=shortcut&new=

That is what actually is requested but when CleanURL is on it won't reach here as the .php?... part gets deleted by the .htaccess.

How does the correct .htaccess has to look like so that the CleanURL gets displayed without .php and actually also stays in the browser bar what it is not doing either?

Robert Lyon's profile picture
Posts: 758

30 June 2021, 14:07

Hi Andi,

Looking at you issues with clean urls this is what I have in my Apache config ( .htaccess configuration may be different, I'm not sure):

    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteRule ^/user/([a-z0-9-]+)/?$ /user/view.php?profile=$1&%{QUERY_STRING}
      RewriteRule ^/user/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?profile=$1&page=$2&%{QUERY_STRING}
      RewriteRule ^/group/([a-z0-9-]+)/?$ /group/view.php?homepage=$1&%{QUERY_STRING}
      RewriteRule ^/group/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?homepage=$1&page=$2&%{QUERY_STRING}
    </IfModule>

And it works as expected.

But I think there might be some mis-understanding on what the clean urls are meant to do

The 2nd rule is not meant to go to any page in Mahara (eg resume) but is mean for pages created by the user (found under Pages and Collections section), eg if my name is Bob and a I make a page called Cats then the clean url will be /user/bob/cats and that will show me the page I made.

If you are wanting clean urls to go to other places with in Mahara you can add your own custom rules before the 2nd rule, eg to go to resume page via /user/bob/resume you could add the rule

      RewriteRule ^/user/([a-z0-9-]+)/resume/?$ /artefact/resume/index.php?%{QUERY_STRING}

or if you wanted to go to files section

      RewriteRule ^/user/([a-z0-9-]+)/files/?$ /artefact/file/index.php?%{QUERY_STRING}

Note doing this will mean if a person creates a page called Resume or Files then they couldn't reach it via cleanurls.

Ideally there would be some reserved words in Mahara when generating cleanuls for pages made by the user so that if they made a page called 'Resume' it would create the cleanurl as /user/bob/resume-1 to avoid the potential clashes with webserver settings.

Cheers

Robert

Andi Becker's profile picture
Posts: 68

30 June 2021, 15:33

Thanks Robert

Yes your .htaccess rules are the same as mine but they have the problem that the URL does not stay in the browser bar.

i.e. I type:

https:/ /montessori.contact/u/andibecker
I get directed to that URL but which immediately directs to the difficult to read on - https:/ /montessori.contact/user/view.php?profile=andibecker

but what is needed is that it actually stays on the clean URL format https :/ /montessori.contact/u/andibecker

Now next a user can easily type in https :/ /montessori.contact/u/andibecker/resume (or whatever page it is which he has created) This keeps links also very short for mailings i.e. if you have to mail your resume. Your idea with resume-1 etc is by the way very good as it would be VERY useful to be able to create several even different looking resumes - but to make that possible also the resume blocks have to be modified (but that is not related to clean URL and I will write about it in another post)

So instead of keeping https :/ /montessori.contact/u/andibecker/resume it again flips over to https:/ /montessori.contact/view/view.php?profile=andibecker&page=resume which is nearly double as long as the clean URL link.

So how to keep the cleanURL in the browser?

Your additional rewrites for resume builder and other "system" pages is great and it would be great if Sahara could provide that. For i.e. a Support team it is a headache to have to explain - i.e. in Thai Language even - the whole path to a certain system page with all question marks and equal signs etc, instead having a cleanURL for those too would make it pretty simple - perhaps even like it is done in Wordpress which redirects any request i.e to "resume" subpath to the correct page, that way also much less 404 errors will appear.

Unfortunately until now I cold not figure out the correct rewrite rules to make that happen.

1. The CleanURL stays in the browser bar and does NOT get replaced by the original path
2. The .php element gets deleted in the paths properly so that also still other paths are working - currently when I add 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]   

all .php endings get removed which looks nice but unfortunately it produces a lot of errors because links to other system pages seem to need that .php ending until now - probably they could be modified too but where (if hardcoded perhaps in the templates - need to check that)

3. A subpath - even parts of a subpath - get automatically assigned to existing and visible pages
4. The system is checking that system pages won't get used as user created page names.
5. It would be nice to have the "user" path element even replaced, so that like in facebook a username appears right behind the domain name. and of course restricted System page names can't be used as User pages - while actually those pages could be also visible as system pages (which means in a subpath) instead of having the user names appearing after a subpath element.

Kristina Hoeppner's profile picture
Posts: 4731

04 July 2021, 20:29

Hi Andi,

Can you please check our demo site? We use clean URLs there with the default setup as it is described on the wiki. There the URL is not replaced by the normal one when you go to the page, unless I'm misunderstanding the problem and when the URL changes for you.

Cheers

Kristina

Andi Becker's profile picture
Posts: 68

05 July 2021, 19:25

The problem is only when you add the removal of the .php endings - that simply does not work in Mahara.

Andi Becker's profile picture
Posts: 68

30 June 2021, 17:45

OK Robert, I checked again and your .htaccess is slightly different from mine and it is actually not working here

This is mine which works but unfortunately always replaces the URL again with the old long view.php one

RewriteRule ^u/([a-z0-9-]+)/?$ .../user/view.php?profile=$1&%{QUERY_STRING} [L]
RewriteRule ^u/([a-z0-9-]+)/([a-z0-9-]+)/?$ .../view/view.php?profile=$1&page=$2&%{QUERY_STRING} [L]
RewriteRule ^g/([a-z0-9-]+)/?$ .../group/view.php?homepage=$1&%{QUERY_STRING} [L]
RewriteRule ^g/([a-z0-9-]+)/([a-z0-9-]+)/?$ .../view/view.php?homepage=$1&page=$2&%{QUERY_STRING} [L]
This here is yours

RewriteRule ^/u/([a-z0-9-]+)/?$ /user/view.php?profile=$1&%{QUERY_STRING}
RewriteRule ^/u/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?profile=$1&page=$2&%{QUERY_STRING}
RewriteRule ^/g/([a-z0-9-]+)/?$ /group/view.php?homepage=$1&%{QUERY_STRING}
RewriteRule ^/g/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?homepage=$1&page=$2&%{QUERY_STRING}

But that one isn't working here on 21.04.2-testing

I therefore experimented a bit more and found out that if I write the following:

RewriteRule ^u/([a-z0-9-]+)/?$ /user/view.php?profile=$1&%{QUERY_STRING} [L]
RewriteRule ^u/([a-z0-9-]+)/resume/?$ /artefact/resume/index.php?%{QUERY_STRING} [L]
RewriteRule ^u/([a-z0-9-]+)/files/?$ /artefact/file/index.php?%{QUERY_STRING} [L]
RewriteRule ^u/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?profile=$1&page=$2&%{QUERY_STRING} [L]
RewriteRule ^g/([a-z0-9-]+)/?$ /group/view.php?homepage=$1&%{QUERY_STRING} [L]
RewriteRule ^g/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?homepage=$1&page=$2&%{QUERY_STRING} [L]


It is keeping the URLs in the browser bar which is great. The difference to yours is that at the beginning the slash is missing behind ^

Yours is 
RewriteRule ^/user/ which did not work here
and mine is
RewriteRule ^user/ or like in my case RewriteRule ^u/ and that is working 
always followed by the rest from above.

The reload was actually caused by the fact that I had entered the https:/ /montessori.contact/ always again
Skipping that and writing only the path which should get rewritten keeps the URL in the Browserbar.

In the example above I added already the two lines you mentioned with "resume" and "files" which works good
and for the customers Resume Pages I actually call them now Curriculum Vitae. short cv0, cv1, cv2, cv. and curriculum-vitae

Thanks for your tip!

I added also a training slash, looks much better now.

Next I have to dig more into getting rid of all those /index.php and index.php? 
and finally also of all other .php and .php? endings in the Browserbar.

Currently the complete .htaccess looks like that:

<IfModule mod_rewrite.c>

RewriteEngine on

# Adding a trailing slash
    RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 
# Not working until now to get rid of the .php endings
    #RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
#RewriteRule ^ %1 [R,L]

    # if redirected to url cleaner, redirect to actual lookup file and
# these lines will keep the clean url visible in the browser
RewriteRule ^u/([a-z0-9-]+)/?$ /user/view.php?profile=$1&%{QUERY_STRING} [L]
    RewriteRule ^u/([a-z0-9-]+)/resume/?$ /artefact/resume/index.php?%{QUERY_STRING} [L]
    RewriteRule ^u/([a-z0-9-]+)/files/?$ /artefact/file/index.php?%{QUERY_STRING} [L]
RewriteRule ^u/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?profile=$1&page=$2&%{QUERY_STRING} [L]
RewriteRule ^g/([a-z0-9-]+)/?$ /group/view.php?homepage=$1&%{QUERY_STRING} [L]
RewriteRule ^g/([a-z0-9-]+)/([a-z0-9-]+)/?$ /view/view.php?homepage=$1&page=$2&%{QUERY_STRING} [L]
   
# do not do anything if already existing file, symbolic link or directory   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L] 

# needs testing - not sure if it works
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]

</IfModule>
7 results