Exclude wordpress from .htaccess rules - wordpress

I have a testing web where there is a testing directory lets say 'test' which contains wordpress directory lets say 'mywordpress', test and his content - excluding the mywordpress - is handled by its own .htaccess - I need the .htaccess to do nothing with the url that goes mydomain.com/test/mywordpressXX (XX can be "/" or "/anything...."
Ive tried something but this .htaccess still works with test content, but throws Internal 500 error when I am trying to reach WP admin:
RewriteEngine On
RewriteBase /test/
DirectorySlash On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ $1/ [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/mywordpress/?$
RewriteRule ^([^/?]+)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/mywordpress/?$
RewriteRule ^([^/?]*)/([^/?]*)$ $1.php?$1=$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/mywordpress/?$
RewriteRule ^([^/?]*)/([^/?]*)/([^/?]*)$ $1.php?$2=$3
What am I doing wrong? Or how is it done correctly ?
Thanks.

Try this .htaccess:
DirectorySlash On
RewriteEngine On
RewriteBase /test/
RewriteRule ^mywordpress(/|$) - [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ $1/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ $1.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]*)/?$ $1.php?$1=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]*)/?$ $1.php?$2=$3 [L,QSA]

Oh ! Silly me ! I forget about the RewriteBase /test/ you just have to make the exclude rule this way:
RewriteCond %{REQUEST_URI} !mywordpress/?$
There was an additional slash:
RewriteCond %{REQUEST_URI} !/mywordpress/?$

Related

HTACCESS rewrite if multiple cookies found

I'm scratching my head trying to do make a htaccess redirect in case of a cookie is found.
I have several directories /fr-be/, /nl-be/, /en/, ...
When a user visits a page in those directories a cookie named "lang" is dropped with the corresponding directory name so 'fr-be', 'nl-be', 'en', ... as value.
If the user manually type the url : 'https://testme.com' and if the cookie is found it should be redirected to the corresponding dir.
If there is no cookie found, it should be redirected to a default dir '/en/'
If there is something else than '/en/' like https://testme.com/en/test-page/ it should not be redirect.
It is a wordpress that's why there is a ". /index.php [L]" at the end.
I can't use php redirect because the website is on a static (strattic) server
Thanks for you help !
Here is my code :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_COOKIE} lang=fr-be
RewriteRule ^/$ /fr-be/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_COOKIE} lang=nl-be
RewriteRule ^/$ /nl-be/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_COOKIE} lang=en
RewriteRule ^/$ /en/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/$ /en/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Eliminate folder name from Urls

I have WP and Laravel6 with structure.
my_site/
.htaccess
wp/
laravel/.htaccess
and virtualhost
<VirtualHost subdomain.local:777>
DocumentRoot "c:\xampp\htdocs\my_site"
ServerName subdomain.local
</VirtualHost>
As I want to serve landing page from WP, I do bit changes in root .htaccess to remove wp from url
RewriteEngine on
# remove wp from urls
RewriteCond %{HTTP_HOST} ^subdomain.local:777$
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^subdomain.local:777$
RewriteRule ^(/)?$ wp/index.php [L]
now subdomain.local:777 shows wp landing page.
Next I want to eliminate laravel folder from urls which are serving from laravel ie:
subdomain.local:777/laravel/login to subdomain.local:777/login
subdomain.local:777/laravel/profile to subdomain.local:777/profile
and so on..
for that I add following into laravel/.htaccess but it crash all routes..
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^laravel/(.*)$ /$1 [L,NC,R]
with error
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
subdomain.local
Apache/2.4.37 (Win32) OpenSSL/1.1.1 PHP/7.2.12
additionally my laravel/.htaccess file also configuring css/js/image/fonts to work like so
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt|\.woff|\.woff2|\.ttf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|google_map|image_compressor|admin-files|fontawesome-free|webfonts)/(.*)$ public/$1/$2 [L,NC]
or do I need to edit in c:\xampp\apache\conf\httpd.conf
Finally solved by bit changes in root .htaccess. such that the final version of .htaccess is now
RewriteEngine on
# remove wp from urls
RewriteCond %{HTTP_HOST} ^subdomain.local:777$
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^subdomain.local:777$
RewriteRule ^(/)?$ wp/index.php [L]
# Rewrite Laravel Routes
RewriteCond %{REQUEST_URI} !^/login [OR]
RewriteCond %{REQUEST_URI} !^/profile
RewriteRule ^(.*)$ laravel/public/$1 [L]

Removing a trailing character at the end of a URL using htaccess

I have a url:
www.example.com/tattoo-ink-radiant-colors-teal/
I need it to change to
www.example.com/ink-wineberry/
so far I have
the following in my htaccess as a temporary fix
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ink
RewriteRule -1oz/ /ink [R=301,L]
edit* to make it simpler here are a few more examples
tattoo-ink-radiant-colors-teal-1oz/ should be tattoo-ink-radiant-colors-teal/
tattoo-ink-radiant-super-white-1oz/ should be tattoo-ink-radiant-super-white/
It's ok with:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-1oz/?$ $1/ [R=301,L]

Mod Rewrite Create Fake Or Hide Wordpress Directory

I would like to fake or even hide my wordpress directory from
mysite.com/wp-content/themes/twentyfourteen/page.php to mysite.com/directory/page.php
or even mysite.com/wp-content/themes/twentyfourteen/page.php to mysite.com/fake1/fake2/fake3/page.php
Within my .htaccess file im using the following commands:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wp-content/themes/twentyfourteen/([^/]+)$ /fakedirectory$1 [L]
I;ve also tried
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wp-content/themes/twentyfourteen/([^/]+)$ /fakedir1/fakedir2/fakedir3$1 [L]
But for some reason this is not working... Any help would be appreciated!! Thanks
You're doing the opposite.
Try this way (assuming your htaccess is in root folder)
RewriteCond %{THE_REQUEST} \s/wp-content/themes/twentyfourteen/([^\s]*) [NC]
RewriteRule . /fakedirectory/%1? [R=301,L]
RewriteRule ^fakedirectory/(.*)$ /wp-content/themes/twentyfourteen/$1 [L]

wordpress change to friendly URL with variable using htaccess

I have a wordpress site with a page template and 1 variable call uid (user id) , and I wanna change it to friendly url.
from
http://localhost/forum/edit-profile/?uid=1
to
http://localhost/forum/edit-profile/1
or
http://localhost/forum/edit-profile/uid/1
P/S: wordpress already has a .htaccess file , i just wanna add some additional codes to this.
I tried these solutions, but they are not working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forumengine/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forumengine/index.php [L]
RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
</IfModule>
Add this to your .htaccess rules
RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
This would redirect /forum/edit-profile/?uid=1 to /forum/edit-profile/1 and back.
EDIT : (with wordpress rules they should go like)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forumengine/
RewriteRule ^index\.php$ - [L]
RewrieCond %{QUERY_STRING} !no-redir [NC]
RewrieCond %{QUERY_STRING} uid=([^&]+) [NC]
RewriteRule ^(.*/edit-profile)/$ $1/%1 [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*/edit-profile)/(\d+)$ $1/?uid=$2&no-redir [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forumengine/index.php [L]
</IfModule>

Resources