Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Suppress a directory name in url (.htaccess) |
|
Author |
|
Otomatic
Joined: 01 Sep 2011 Posts: 212 Location: Paris, France, EU
|
Posted: Thu 03 Feb '22 14:29 Post subject: Suppress a directory name in url (.htaccess) |
|
|
Hi,
It is not for me so I could not check directly the result.
Following several restorations and the passage of a local site in VirtualHost, it remains in this site urls when it was used in folder of localhost ('http://localhost/wordpress/')
Let me explain:
The vast majority of the site's calling urls are of the style:
http://mysite/folder/page|js|css|img
but for some of them, an old non-existent folder name is interposed:
http://mysite/wordpress/folder/page|js|css|img
So I would like to remove, if it exists, '/wordpress' from all urls.
I'm not an expert on rewrite rules, but I did come up with this:
Code: | RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(site|js|medias|css|images)/
RewriteRule ^(.*)$ /wordpress/$1 [L]
|
Do you think this is what is needed?
Wouldn't it be better to put this in the VirtualHost definition?
Thank you. |
|
Back to top |
|
tangent Moderator
Joined: 16 Aug 2020 Posts: 348 Location: UK
|
Posted: Thu 03 Feb '22 16:38 Post subject: |
|
|
As written, your rule adds /wordpress as a prefix to each URL, not remove it. Believe the following rewrite rule should do what your want.
Code: | RewriteRule ^/wordpress(/.*)$ $1 [L,NC,NE,QSA]
|
The additional flags options are for a case insensitive match, no hexcode escaping of special characters, and appending any query string present to the rewritten URL. Basically, leave the rest of the rewritten request unchanged. See flag options here - https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
If you need to qualify this rewrite for certain sub folders, you can precede it with a rewrite condition of the form:
Code: | RewriteCond %{REQUEST_URI} (site|js|medias|css|images)
|
And yes, I would place this rewrite rule in the VIrtualHost context. The documentation describes how the pattern matching varies, depending on where the rule is placed. |
|
Back to top |
|
Otomatic
Joined: 01 Sep 2011 Posts: 212 Location: Paris, France, EU
|
Posted: Fri 04 Feb '22 10:09 Post subject: |
|
|
Hi,
Thanks a million.
It works perfectly and it allowed my friend to recover his entire site and make the necessary changes. |
|
Back to top |
|
|
|
|
|
|