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]
Related
i have my main site with the next .htaccess
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
and in my subdomain i just install wordpress, but the rewrite rules of my main site broke the navigation of my wordpress, how can exclude my subdomain from the rules of my main domain?
i am try this but dont work
# don't apply any rewrites to the subdomain
RewriteCond %{HTTP_HOST} ^subdomain\.mysite\.com$
RewriteRule .* - [L]
and in the .htaccess of my wordpress forlder i have this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
any idea how can fix this?
thanks in advance
Use in your main site .htaccess
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{HTTP_HOST} !^subdomain\.mysite\.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{HTTP_HOST} !^subdomain\.mysite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
I've got my WordPress installed in /apache_installation/dir1/dir2/wp_dir/ and it's accessed through http://myIp/dir1/dir2/wp_dir/
I'd like the users to view only the url http://myIp/dir1/dir2/ but the files continue being served from the /wp_dir/ subfolder.
I've tried so many choices, all from stackoverflow, and all of them preceded of
php_value magic_quotes 0
php_flag magic_quotes off
php_value magic_quotes_gpc 0
php_flag magic_quotes_gpc off
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?myIp/dir1/dir2/$
RewriteRule !^wp_dir/ /wp_dir%{REQUEST_URI} [L]
or
RewriteRule ^$ wp_dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ wp_dir/$1
or
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wp_dir/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^wp_dir/)^(.*)$ /dir1/dir2/wp_dir/$1 [L,NC,R=301]
or
RewriteRule ^/wp_dir/(.*)$ http://myIp/dir1/dir2/wp_dir/$1 [L,R=301]
or
RewriteCond %{THE_REQUEST} ^GET\ /wp_dir/
RewriteCond %{HTTP_HOST} ^(www\.)?myIp/dir1/dir2$
RewriteRule ^wp_dir/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?myIp/dir1/dir2$
RewriteRule !^wp_dir/ wp_dir%{REQUEST_URI} [L]
or
RewriteRule !^wp_dir/ /dir1/dir2/wp_dir%{REQUEST_URI} [L,NC]
or
RewriteCond %{REQUEST_URI} !^wp_dir/
RewriteRule ^(.*)$ wp_dir/$1 [L]
or
RewriteCond %{HTTP_HOST} ([^/]+)\.myIp.*
RewriteCond %{REQUEST_URI} ^/([^/]+)$
RewriteRule .* http://myIp/dir1/dir2/wp_dir/%2 [L]
or
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wp_dir/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
or
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^wp_dir/)^(.*)$ /dir1/dir2/wp_dir/$1 [L,NC]
and followed by
ErrorDocument 404 /404page.php
Inside wp_dir, there's another htaccess (generated by wordpress) with the code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dir1/dir2/wp_dir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dir1/dir2/wp_dir/index.php [L]
</IfModule>
I've touched nothing in it.
None of the root htaccess choices work for me, everyone with different errors. Some of them gives a "Not found" error, other displays the core of the wordpress site but with the content of the 404 page.
I'm stuck at this point, as you can see I'm not used to this file.
It seems that your entire site is in the wordpress folder - what you could maybe do is copy all of the files inside the main folder, and paste them in the root folder - afterward deleting the wordpress folder.
Ok. I'm desperate.
Basically when i add the #Force https lines below it's then sending my shop.mydomain.com/wp-admin to mydomain.com/wp-admin Aaaaaah.
My wordpress shop site lives inside the main domain folder (inside the other wordpress site) i.e. public_html/mydomain(wordpress install)/shop(wordpress install)
I have a Wildcard SSL installed on the www.mydomain.com (which handles 1st level subdomains). The SSL part seems to be working fine.
Here is the .htaccess inside the folder /shop:
#Send www to https
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.shop.mydomain.com$ [NC]
RewriteRule ^(.*)$ https://shop.mydomain.com/$1 [R=301,L]
#Force Https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
etc etc
# END WordPress
And inside the main domain folder public_html/mydomain:
#.htaccess WildCard SSL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shop.mydomain.com$
RewriteCond %{REQUEST_URI} !^/shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /shop/$1
RewriteCond %{HTTP_HOST} ^shop.mydomain.com$
RewriteRule ^(/)?$ shop/index.php [L]
# BEGIN WordPress
etc etc
# END WordPress
Would be grateful for any advice. =>
Place the following in the .htaccess for the domain
# .htaccess WildCard SSL + wordpress + subdomain
RewriteEngine on
RewriteCond %{HTTP_HOST} ^shop.domain.com$
RewriteCond %{REQUEST_URI} !^/shop/
RewriteRule ^(.*)$ /shop/$1
RewriteCond %{HTTP_HOST} ^shop.domain.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(/)?$ shop/index.php [L]
# BEGIN WordPress for main domain
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.app.domain.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1
The problem: app.domain.com is working without problems, but as soon as you add a subfolder like app.domain.com/folder you get the Wordpress tag page.
What am I doing wrong?
The problem is here
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule (.*) /app/$1
Which says that if the URL does not start with /app/ (which /folder doesn't) it must be rewritten to /app/folder. After that rewrite the RewriteRules will be processed again, and the wordpress section will find that folder doesn't exist and fire up wordpress for you.
The way to resolve this issue is to change the last block to
RewriteCond %{HTTP_HOST} ^(www\.)?app\.domain\.com$
RewriteRule %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule .? app%{REQUEST_URI} [L]
This tells apache it may only rewrite to /app/folder if /folder does not exist.
(and you can remove the whole stuff for app.domain.com, this block handles both www.app.domain.com as well as app.domain.com
I want to install WordPress in subdirectory and remove index.php in permalinks.
The server is IIS 6.0, support rewrite.
My webserver has the following directories:
webroot
--wp [wordpress folder]
webroot/.htaccess
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
webroot/wp/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #3
It works when I visit a.luckyet.com and a.luckyet.com/hello-world.html
But it does not work when I visit a.luckyet.com/wp-login.php or a.luckyet.com/wp-admin
The #3 works fine, but #1 and #2 can not work properly. Then I saw here and change the content of webroot/wp/.htaccess to:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
It still does not take effect. Can anyone help me? Thanks in advance!
Update:
ISAPI_Rewrite version is 3.0.
All code in webroot/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
All code in webroot/wp/.htaccess:
RewriteEngine on
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule wp-(.*) wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule (.*) index.php/$1 [L]
Wordpress permalink is:
/%postname%.html
Thus, Wordpress can work fine when visit http://a.luckyet.com/ or http://a.luckyet.com/hello-world.html
Question:
If there is a real file like a.html in webroot/wp/, like webroot/wp/a.html, wordpress 404 error will be reported when visit http://a.luckyet.com/a.html, . How can I fixed this?
You're dynamically rewriting the URLs with the .htaccess file and WordPress settings to tack on the .html extension - any files that are "real-life" .html files are being handled upstream by the IIS Handler Mappings.
You'll have to update your Handler Mappings in IIS for .html files especially to direct the requests directly to the physical file.