0

I have decided to ditch Wordpress and move to Pico CMS instead.

Now I'm struggling with getting the URL rewriting done correctly.

I have managed to rewrite the query string from eg. https://www.example.org?page to https://www.example.org/page using RewriteRule ^(.*) ?$1 [L], but now I also want it rewritten if there is a query string.

Example:

If https://www.example.org?page is requested it loads just fine, but I want to have it rewritten as https://www.example.org/page - at least in the location bar.

I have tried several variations but to no avail. I suck at regular expressions...

RewriteCond %{QUERY_STRING} !^$ RewriteRule ^\\?/(.*)$ $1

Nope

RewriteRule (^\?$) https://tanghus.net/$1 [NC,R=301,L] RewriteRule ^.*$ https://tanghus.net/? [NC,R=301,L]

no dice

RewriteCond %{QUERY_STRING} . RewriteRule ^$ %{QUERY_STRING} [R,L]

Pfff

RewriteCond %{THE_REQUEST} \?\sHTTP [NC] RewriteRule ^ %{REQUEST_URI} [L,R]

Giving up :(

1 Answer 1

2

You can use this Rule

RewriteEngine on

# externally  redirect from /?page to /page
RewriteCond %{THE_REQUEST} /\?([^\s]+) [NC]
RewriteRule ^/?$ /%1? [L,R]
# internally map /page to /?page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.+)$ /?$1 [L]
Sign up to request clarification or add additional context in comments.

1 Comment

That absolutely did the trick! Thanks a lot. I really should have paid more attention to RegExps 20+ years ago ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.