jchunick's picture

Specs:

Apache/2.2.16 (Debian) Server

Wordpress 4.x

---------------

I'm trying to convert this 'vanity URL' that our graphic design guy created for print ads:

http://tbrhsc.net/PaediatricORtour/

to this:

http://tbrhsc.net/paediatricortour/

I figured a Redirect would work for this. I'm using Wordpress, and this is what I originally added to my .htaccess file in the wordpress root folder:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect ^PaediatricORtour/?$ /paediatricortour/

....

</ifModule>

-----------------------

However, this didn't do anything but send me to my 404 page.

------------------------

So, looking online to find something to convert to lower case (which is ultimately what I'm trying to do), I found this suggestion:

Redirect a URI to an all-lowercase version of itself

RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*) ${lc:$1} [R]

link: http://httpd.apache.org/docs/2.2/rewrite/rewritemap.html#int

I'm getting a 500 internal error when trying to add those two lines to my .htaccess file just below the line: RewriteEngine On.

I've tried variations, like this one:

RewriteMap tolower int:tolower
RewriteRule  ^([^/]+)/?$  /${tolower:$1}

or this one:

RewriteMap tolower int:tolower
RewriteRule  ^([^/]+)/?$  /${tolower:$1} [R=301,L]

link reference: http://stackoverflow.com/questions/2923658/convert-to-lowercase-in-a-mod...

... I've also added this line above those:

RewriteBase /

But all of them give me a 500 Internal Server Error.

... I've even tried adding those lines and then rebooting.

------------------------------------------------------------------------

So, can someone tell me what's going on?... is there something obvious I'm missing?... maybe Apache is somehow modified by Turnkey to not use that RewriteMap function...  I'm at a loss when nothing I try seems to work.

Thanks for any assistance.

Forum: 
Jeremy Davis's picture

The only real recommendation I can give is try checking the Apache error log (IIRC /var/log/apache2/error.log) to see if there is more info there...

TO just be sure I understand what is happening; the page tbrhsc.net/PaediatricORtour/ actually exists? And the tbrhsc.net/paediatricortour/ also exists? Actually I just had a quick look and answered the question myself...

It seems that there is already some redirection going on. I'm not sure where its coming from (may perhaps be something to do with WordPress itself?) I just tried browsing to http://tbrhsc.net/paediatricortour/ and it redirected me to http://tbrhsc.net/PaediatricORtour// also FWIW http://tbrhsc.net/paediatricorTOUR/ also redirects to http://tbrhsc.net/PaediatricORtour/... So obviously there is some redirection taking place already. I suspect that is why you were getting a 500 error. By adding a redirection of tbrhsc.net/PaediatricORtour/ to tbrhsc.net/paediatricortour/ you have created a redirection loop!

I haven't used WordPress much but in Drupal those 'vanity' urls can be manually edited... Why not just see if you can manually edit the url itself?

jchunick's picture

Hi Jeremy,

Thanks for taking a look. Sorry for wasting your time a bit. I ended up doing the fix I didn't want to do - namely, renaming the folder to /PaediatricORtour/ - which is why it's working.

Initially I posted because I realized that after seeing this issue crop up it would be best to have the server take any/all requests coming in and converting the uri to lowercase. That way, in the future, this issue wouldn't rear it's ugly head again. 

So, to also reiterate and address your last point about a redirect loop - at the time I posted the question there wasn't one as there wasn't a redirection happening. The current fix is through renaming the directory so that it has the proper case and then redirecting in WordPress... not the ideal solution I want.

Again, thanks for putting some time into it. I'm sorry I didn't update things... but I had a url that was in the public (ie. marketing material had that url on it) and at the time was focused on finding a quick solution.

I'd still like to figure out why the rewrite module is not working properly for me or at least get someone to confirm that their box works with the rules I want to use and what syntax they are using.

Regards,

Josh

Jeremy Davis's picture

Thanks for posting back with an update! :)

FWIW if you have some time and want to have a play with it you could download the appliance (as a VM or an ISO) and install locally on virtualbox. Then add an entry to your hosts file (something that won't ever use) and set the same domain on the VM. Then fiddle and test with no real world consequence! :)

OnePressTech's picture

RewriteRule ^PaediatricORtour$ http://tbrhsc.net/paediatricortour/ [NC,R=301,L]

Cheers,

Tim (Managing Director - OnePressTech)

Jeremy Davis's picture

Helpful as always!

Add new comment