0

Good morning everyone,

I'm reaching out for assistance with rewriting a URL. My objective is to modify the URL https://voorbeeld.nl/pagina/lid-worden.html to https://voorbeeld.nl/lid-worden by removing the /pagina/ folder from the URL.


Here are some of the RewriteRules I've attempted:

RewriteEngine On

#Rewrite from /pagina/lid-worden.html to /lid-worden
RewriteRule ^pagina/(.*)\.html$ /$1 [R=301,L]

RewriteEngine On

#Rewrite from /pagina/lid-worden.html to /lid-worden
RewriteRule ^pagina/lid-worden\.html$ /lid-worden [R=301,L]

RewriteEngine On

#Rewrite from voorbeeld/pagina/lid-worden.html to /lid-worden
RewriteRule ^voorbeeld/pagina/lid-worden\.html$ /lid-worden [R=301,L]

However, I haven't achieved success with these attempts as it shows
The requested URL was not found on this server. when visiting https://www.voorbeeld.nl/lid-worden


The folder voorbeeld contains the following folders & files

  • /assets
  • /pagina (contains the file lid-worden.html)
  • .htaccess
  • index.html

I must admit that my knowledge and understanding of URL rewriting are quite basic. Therefore, I'm really hoping to receive some assistance in order to achieve the desired success in this area. Any guidance or support would be greatly appreciated.

If there is any additional information I have missed or overlooked, please do not hesitate to let me know. I will make every effort to acquire the necessary details to address your requirements effectively.


Important Note
I want to draw your attention to an important detail. The domain name and folder name referred to as "voorbeeld" in this text are simply examples I have chosen to protect the privacy of the actual domain or website. It's crucial to understand that these names are not real and are used solely for demonstration purposes.

  • None of your rule patterns actually match the path of the requested URL, `lid-worden`. It looks like your understanding of how this works, might be exactly the "wrong way around"? You need to match the _incoming_ URL, and then specify what you want that to get rewritten to internally. – CBroe Jun 06 '23 at 10:20
  • Thank you, @CBroe for committing. Could you please provide me with an example that offers a more visual perspective? – Resstrictionss Jun 06 '23 at 10:34
  • If you don't want to write specific rules that explicitly "list" each possible URL, then you need to use a wildcard match, basically just match `.*` - "anything". (Or a bit more specific, f.e. excluding `/`, if you don't want this to work for anything in "sub-folders.") But you don't want to rewrite for anything that matches a physically existing file (think, `logo.jpg`- if that actually exists as a file, then you do not want to rewrite it to anything like `pagina/logo.jpg.html`, that would make little sense.) – CBroe Jun 06 '23 at 10:39
  • So usually, one uses a RewriteCond before the rule, to check that what was requested does not match an existing file or folder. An example for that you can find in the general explanation on URL rewriting, https://stackoverflow.com/q/20563772/1427878 – CBroe Jun 06 '23 at 10:39
  • "The domain name and folder name referred to as "voorbeeld" in this text are simply examples" - Then please use `example` in your question (as defined in RFC2606). It's also confusing having the domain and subdirectory of the same name, if that is not the case. Use `foo`, `bar`, `baz` as example names/dirs - names that are commonly used as fictitious examples in documentation. – MrWhite Jun 06 '23 at 11:11
  • 1
    @CBroe Apologies for the delayed response. I got a bit lost in the link you provided, and you were absolutely right—it was the wrong way around. After carefully reading through the information and consulting my hosting provider's guide on this topic, I was able to successfully make it work. I sincerely appreciate the time you took to assist me and for providing valuable information. It was a challenging journey to figure it out, but your three comments on my post were instrumental in helping me find a solution. Thank you once again for your support. Have a great day or night, and cheers, Ress. – Resstrictionss Jun 06 '23 at 16:26

0 Answers0