Not logged in. · Lost password · Register
Forum: General Help and Support Installation and Configuration RSS
URL rewrite for old link?
Page:  1  2  next 
Avatar
mekineer #1
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
Subject: URL rewrite for old link?
If you have rewrite correctly enabled for "nice URLs" , and someone follows an old link to the site's regular URL.  What will be displayed in the browser?

Someone clicking on https://domain.com/doku.php?id=namespace:pagename

Will arrive at:

https://domain.com/doku.php?id=namespace:pagename
OR
https://domain.com/namespace/pagename

???

RewriteEngine on

RewriteBase /
RewriteRule ^dokuwiki/(.*)$ /$1 [R=301,NC,L]

RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

RewriteCond %{https} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

ps.  The site used to be in the subfolder dokuwiki, and now it is at the root folder
Avatar
Michaelsy #2
Member since Jun 2015 · 969 posts · Location: Düsseldorf, Germany
Group memberships: Members
Show profile · Link to this post
What will be displayed in the browser?

Compare this:
https://www.dokuwiki.org/blogroll

with this:
https://www.dokuwiki.org/doku.php?id=blogroll
By Patreon.com a few eurons can be fed into the code phasers of
the DokuWiki engine. Besides, Andi's posts are worth reading.
Avatar
mekineer #3
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
I guess to be more specific, I meant what will be displayed as the URL.  I was hoping it would always forward to the "nice URL", but apparently not.

Does it confuse a search engine?
Avatar
Michaelsy #4
Member since Jun 2015 · 969 posts · Location: Düsseldorf, Germany
Group memberships: Members
Show profile · Link to this post
Quote by mekineer:
Does it confuse a search engine?

Anyway, that's not a serious problem for a search engine.

Edit a week later:
After thinking about it for a while, I come to the conclusion, at this point are no problems at all to fear with search engines.
By Patreon.com a few eurons can be fed into the code phasers of
the DokuWiki engine. Besides, Andi's posts are worth reading.
This post was edited on 2019-06-04, 10:33 by Michaelsy.
Avatar
mekineer #5
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
https://stackoverflow.com/questions/5083811/beautified-url…

Anyone familiar with Regex, to 301 redirect to the "nice url's"?
Avatar
mekineer #6
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
RewriteRule ^doku.php\?id=([^\:]*)\:(.+)$ $1/$2 [R=301,L]

What am I doing wrong?  Edit: I have this backwards.  I'm trying to undo what the Rewrite Rules do.
This post was edited on 2019-05-28, 10:51 by mekineer.
Avatar
schplurtz (Moderator) #7
Member since Nov 2009 · 463 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
Hi,

first of all, never, ever, do 301 redirect without a long testing period. 301 are such redirects that a client (be it googlebot, or someone's browser) will not retry the original URL once it got a new one with 301 redirect. So if you make an error or you later discover some issue, you cannot undo that for clients that have already learnt the new URL.

What am I doing wrong?  Edit: I have this backwards.  I'm trying to undo what the Rewrite Rules do.
rewrite rules do not rewrite query string (the part after the '?').


In your case, you basically want to rewrite :
_______/doku.php?_____id=page:name_______
to
_______/page:name?_____ _________
So, you need to remove id from the query string and replace doku.php with its value.

The first example in apache article "Redirecting and Remapping with mod_rewrite" shows how to remove a query string parameter. Given that, you could try this, just before the other rewrite rules :

# Remove id=??? and replace doku.php with ???
RewriteCond "%{QUERY_STRING}" "(.*(?:^|&))id=([^&]*)&?(.*)&?$"
RewriteRule "(^|/)doku.php$"            "$1%2?%1%3" [R=302,L]

Completely untested.
Avatar
schplurtz (Moderator) #8
Member since Nov 2009 · 463 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
In reply to post #6
Quote by mekineer:
Edit: I have this backwards.  I'm trying to undo what the Rewrite Rules do.

Yes and no.

With [R=302,L] (or 301) you are doing an external rewrite. The server sends an answer that says
"instead of «doku.php?id=blablabla», try «blablabla»"
When the browser comes back, it asks for «blablabla», so the first rewrite rule doesn't apply.
What happens next, that transforms the url back to «doku.php?id=blablabla» is an internal rewrite.
This rewrite is just done so that, in the end, the web server knows what to do with the request ; the
client is completely unaware of this rewrite.
Avatar
mekineer #9
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
RewriteEngine on

RewriteBase /

RewriteCond %{https} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

RewriteRule ^dokuwiki/(.*)$ /$1  [R=301,L]

RewriteCond %{QUERY_STRING} ^(id=)([^\:]*)\:(.*)$
RewriteRule ^doku\.php$ %2/%3 [R=301,L,QSD]

## RewriteCond %{REQUEST_URI} ^data/media/(.*)$
RewriteCond %{REQUEST_URI} ^data/pages/(.*)$
RewriteRule  .?  -  [S=6]

RewriteRule ^(_?.+)_(.*)_(.*)_(.*)_(.*)_(.*)_(.*)$ /$1-$2-$3-$4-$5-$6-$7 [R=301,L]
RewriteRule ^(_?.+)_(.*)_(.*)_(.*)_(.*)_(.*)$ /$1-$2-$3-$4-$5-$6 [R=301,L]
RewriteRule ^(_?.+)_(.*)_(.*)_(.*)_(.*)$ /$1-$2-$3-$4-$5 [R=301,L]
RewriteRule ^(_?.+)_(.*)_(.*)_(.*)$ /$1-$2-$3-$4 [R=301,L]
RewriteRule ^(_?.+)_(.*)_(.*)$ /$1-$2-$3 [R=301,L]
RewriteRule ^(_?.+)_(.*)$ /$1-$2 [R=301,L]

RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php  [L]
This post was edited 2 times, last on 2019-05-30, 07:22 by mekineer.
Avatar
mekineer #10
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
Let me know if it can be cleaned up some.  Seems to work.
Avatar
Michaelsy #11
Member since Jun 2015 · 969 posts · Location: Düsseldorf, Germany
Group memberships: Members
Show profile · Link to this post
Have you already tried out whether the administration pages are all fully functional? This means that you should make test entries on these pages and check whether they are accepted:

User Manager
Access Control List Management
Extension Manager
    Search & Install
Configuration Settings

Additional you should test whether your section edit buttons work as expected.
By Patreon.com a few eurons can be fed into the code phasers of
the DokuWiki engine. Besides, Andi's posts are worth reading.
This post was edited on 2019-05-29, 13:17 by Michaelsy.
Avatar
mekineer #12
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
Nothing was working, because I made an error (now fixed) by deleting QSA in the next to last line.
This post was edited on 2019-05-30, 05:47 by mekineer.
Avatar
mekineer #13
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
If I use hyphens as word separators in the images, then they don't appear in the pages.  Rename the images with underscores, and everything's ok.

I have the dokuwiki setting to use hyphens as word separators enabled, and I have the underscore-removal and doku.php-removal sections disabled in the htaccess above.


Ok... had to flush the browser cache.  Maybe Ctrl-F5 isn't doing what it's supposed to.  Now maybe things will start to make some kind of sense.
This post was edited 3 times, last on 2019-06-03, 20:22 by mekineer.
Avatar
mekineer #14
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
After enabling the full htaccess (removing the ## commenting before certain code), the images were broken again, (and probably other related to _media, _detail, and _export), so I changed the regex to (_?.+), and now not broken.  I hope no more surprises.  I hope no more teasing.

So, again, in case you are reading this and not sure WTF is the purpose.

In past I had a site that:
  * had dokuwiki in a subfolder instead of root
  * used underscores as a word separator for my own naming of pages and media
  * used ugly URLs

I followed the steps to use Nice Url's, but incoming requests from old links still showed the ugly, so used htaccess regex above to "301" tell user's web browsers and search engines that there is only one page, and to stop asking for the old URLs.

Google, the all powerful, say "underscore bad", unless you are Wikipedia.  So I renamed all my pages and media with hyphens, and used the plugin "orphans wanted" to clean up internal links.  For existing links coming from outside my website to no longer be dead, I used regex to reform the request and provide a 301.  The user's web browser then requests the Corrected Nice URL, and the dokuwiki-supplied-regex does it's thing for the internal request.

Check my work:
http://www.mekineer.com/dokuwiki/doku.…?id=information_t…
should now resolve as:
https://mekineer.com/information-technology/2019-search-en…
This post was edited 2 times, last on 2019-05-30, 08:00 by mekineer.
Avatar
mekineer #15
Member since Mar 2018 · 28 posts
Group memberships: Members
Show profile · Link to this post
RewriteCond %{REQUEST_URI} ^data/pages/(.*)$
RewriteRule  .?  -  [S=6]

This condition was never going to be met, so the underscore removal section would always happen.  I got around the worst of it by using (_?.+), but the underlying problem is still there.
This post was edited on 2019-06-04, 08:23 by mekineer.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next 
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-08-24, 00:36:05 (UTC +02:00)