1

I have a page on my Wordpress website that I want to effectively have a wildcard on the end of the URL.

The URL is "https://www.mywebsite.com/map". I want that same page to be directed too if it is anything like:

  • "https://www.mywebsite.com/map/7690e382-786a-412d-9711-966a708c0a38"
  • "https://www.mywebsite.com/map/ef5ae8ba-fcbd-4184-b501-bd79ecdd4ee2"

I need the URL to keep the segment though, as I have some JS on the /map page that will read it and send the value to an IFrame.

Is this possible via Wordpress admin or via the .htaccess file?

1 Answer 1

1

I was able to get it working by adding the following two lines to my .htaccess, right before the rest of the other WordPress rule

RewriteCond %{REQUEST_URI} ^/map/(.+)$ [NC]
RewriteRule ^(.*)$ /map [L,P]

Bottom of my .htaccess with the rules looked like this:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/map/(.+)$ [NC]
RewriteRule ^(.*)$ /map [L,P]

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
1
  • Your rule can be simplified to a single directive, eg. RewriteRule ^map/. /map [NC,P]. However, proxying the request in this way is very inefficient. There should be a more efficient "WordPress" (non Apache/.htaccess) way of doing this. (NB: You should avoid editing the code in the WordPress code block - if that is what you have done here - since WordPress itself manages this section. Your rule just needs to be near the top of the file, before the # BEGIN WordPress comment marker. It can go before the RewriteEngine On directive - you do not need to repeat this directive.)
    – MrWhite
    Aug 14 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.