Jump to content
lostpanther

Rewrite URL in htaccess to hide certain characters

Recommended Posts

Hi guys
I have a problem and also lack the understanding to put this rewrite rule in place.
I only need to remove these characters from any URL on our website ?rid=

from this:
 

https://rpmdigital.co.uk/coffee/?rid=A611F4

to this:
 

https://rpmdigital.co.uk/coffee/A611F4

The first section is created by wordpress https://rpmdigital.co.uk/coffee/
and last part is created by an Xmpie system ?rid=A611F4
the 6 digit number is dynamic and specific to making the webpage personalised to them.
I have been told by Xmpie support that this can be done in the wordpress .hatches

We use apache and Wordpress.
The code I have in my .htaccess file on our apache server is this.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

is it possible to show me the process as i lack experience

Really appreciate some help on this

Kind Regards
Matt

Share this post


Link to post
Share on other sites

Hey mate,

In htaccess it's pretty simple, but not 100% what WordPress is doing, it routes everything via index it appears. I would hazard a guess at ...

RewriteRule ^coffee/([^/]*)$ /coffee/?rid=$1 [QSA,NC]

... this would make /coffee/?rid=ABC123 display as /coffee/ABC123. You can tighten the regex to only accept number and letters etc but i'm not sure on the possible options for 'rid', see https://httpd.apache.org/docs/2.4/rewrite/intro.html.

Duplicate Content Warning: Both pages would return the same page under different urls, canonical or something.

WordPress Warning: I've zero experience with the magic of WordPress, this might knock its nose out of joint.

Health Warning: Don't drink and drive, you'll spill your drink ;)

Edited by BrowserBugs

Share this post


Link to post
Share on other sites

Hi BrowserBugs
Thank you for your help.
I have added the code to hatches like this.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^coffee/([^/]*)$ /coffee/?rid=$1 [QSA,NC]
</IfModule>
# END WordPress

When i enter the ugly URL into the browser address bar:

https://rpmdigital.co.uk/coffee/?rid=755162


the page still works.

When i enter the friendly URL into the browser address bar:
 

https://rpmdigital.co.uk/coffee/755162

I get an error page.

Am I doing something slightly wrong?

Again many thanks for your time

Kind Regards
Matt

Share this post


Link to post
Share on other sites

Sorry for the delay. I'm 99% sure this is because WordPress shoves everything via index and works it out from there. Chances are then that in WordPress there is some kind of rewrite settings you could play with, I think they are your permalinks, see https://codex.wordpress.org/Using_Permalinks.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • By Web Lad
      Hi from a new member!
      Just wondering what the name is, for the new logo design competition.
      Just that the URL and current logo read "web designer forum" but your emails and title in Google is "web design forum".
      Which is it?
      Dave
       
    • By docchazz
      hi everyone

      i've been using hubspot for my blog, so i create a subdomain blog.domain.com which redirected to my hubspot blog posts

      however, i am discontinuing with hubspot, and have reposted all my blog posts on my my domain www.domain.com

      i am trying to create a htaccess record to redirect all the old links to the new ones.

      something like:
      old address: blog.domain.com/(article slug)
      new address: www.domain.com/2016/10/29/(article slug)
      (yes the date is fixed and the same for all posts, i've created them all today)

      can someone help me with the htaccess record?

      thanx in advance!
    • By protest
      Hello I have installed wordpress in a directory 'test-admin' (mydomain.co.uk/test-admin), unfortunately when I go to that it is redirecting to my 'newdomain' which I don't want it to, none of the other pages are redirecting, they all work fine. In the 'test-admin' directory I have the following htaccess: RewriteEngine On RewriteBase /test-site/ RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] AuthName "test-site" In the main public html directory I have this htaccess:
      RewriteEngine on RewriteRule ^(test-site) - [L] RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [OR] RewriteCond %{HTTP_HOST} ^www.mydomain.co.uk$ RewriteRule ^/?$ "http\:\/\/newdomain\.com" [R=301,L] <ifmodule mod_deflate.c> AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript </ifmodule> So everything on my public html in 'mydomain' i wish to redirect to 'newdomain' except for the 'test-admin' folder....this is working apart from the home page in the test admin folder
       
      Any ideas what I have done wrong? It is wordpress multisite installed in 'test-admin'...latest wp version.
      Many thanks in advance
    • By guycruls
      Hi,
       
      123reg are flagging up to me the opportunity to acquire urls ending in .uk for existing domains of ours that have the more 'traditional' endings .org.uk.
      Is there any value in moving to .uk, notably future proofing?
       
      Many thanks
       
      Guy
    • By newuserphp
      I created a Rule in my HTACCESS file, to hide a sub-folder.
      RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC] RewriteRule ^ /%1/%3 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php [NC,L] The first rule removes all file-extensions : php

      The second rule will hide the folder "Project" from the URL

      Both these rules are working perfectly.

      However, when I tried to add a third rule, to hide another folder, it failed.

      This second folder (Rolan) is in the same location as the "Project" folder, so I assumed that it should work simply by copy-pasting the second rule, and then adding a PREFIX to the beginning of the third rule :
      RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/?([^/]+)/([^/]+)/([^.]+)\.php [NC] RewriteRule ^ /%1/%3 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1/Project/$2.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^gagoo/([^/]+)/([^/]+)/?$ $1/Rolan/$2.php [NC,L] I added the prefix "gagoo" to the third rule.

      Also, I removed the [NC,L] from the end of the second rule, and placed it at the end of the third rule.

      Then, in my PHP code, I wrote the URL as follows : www.example.com/gagoo/Rolan/file_name

      Both the first and second rules are still working. But, for the third rule, I am getting a "FILE NOT FOUND : 404" error.

      The thing is : I wrote a JavaScript code, which opens "file_name" in a "New Window". (Still, I doubt that this could be the reason for the problem)


  • Recently Browsing

    No registered users viewing this page.

  • Member Statistics

    • Total Members
      57,730
    • Most Online
      4,970

    Newest Member
    dbonilla
    Joined
  • Forum Statistics

    • Total Topics
      65,788
    • Total Posts
      454,664
×