React-Redux application on sub-directory using Apache Server - apache

I have deployed react application on the subfolder of apache server
Url Folder: /var/www/html/abc
I have the following .htaccess rules to rewrite requests
RewriteEngine On
RewriteBase /abc
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /abc/index.html [L]
But it is not working Please help me to rewrite the .htaccess rules

Just remove the abc on and place it in the directory:
# To be inside the /Directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Source: https://gist.github.com/santthosh/7dabf08fa3859361ef1e

Related

htaccess redirect to index.html in same (unknown) subfolder

I like to redirect all request to index.html where the .htaccess is placed
Place of .htaccess:
https://example.com/unknown/whatever/.htaccess
This request:
https://example.com/unknown/whatever/article1
should redirect to
https://example.com/unknown/whatever/index.html
It only works for me, when i know the subfolder path:
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /unknown/whatever/index.html [L]
Any idea how to make this work when the subfolder path and count is unknown?
It works for me (requested URL - unknown/whatever/article1)
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ $1/index.html [L]
server files structure:
unknown/whatever/article1/index.html
.htaccess
and this one works for me too (requested URL - unknown/whatever/article1):
RewriteEngine On
RewriteBase /
DirectorySlash Off
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)/(.*)$ $1/index.html [L]
server files structure:
unknown/whatever/index.html
.htaccess
request: unknown/whatever/article1
.htaccess:
RewriteEngine On
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)$ index.html
Files structure:
unknown/whatever/index.html
unknown/whatever/.htaccess

htaccess error leading to loop

I am trying to force SSL on HTACCESS file and all my efforts result in a loop on index.php.
This is my htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My site works fine with this but no SSL.
I tried the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ https://www.fakedomainlollol.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The updated rewrite rule sends the site in a loop.
What is the error? What am I doing wrong here?

Redirect to index.php of .htaccess dir

In .htaccess code is written as
RewriteEngine On
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)?$ /project/index.php/$1 [L]
But this .htaccess is redirecting to index.php of my web root rather than that of the project. I have server which have wordpress installed directly at root (with its own .htaceess) and I have to get the project directory working with that . .htaccess of wordpress is written as below but I dont have access to edit it .
SetEnv PHP_VER 5_TEST
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteRule ^landing-page=([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
How can I force to redirect to index of my project from my .htaccess
Try this code in /project/.htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /project/
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]

simple Apache RewriteCond and RewriteRule issue

I'm trying to follow https://github.com/crwilliams/diary-user-interface/wiki/cachebusting
If I set my HTML code to:
href="/myDir/myFile.2013103000.html"
and add to .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(html)$ $1.$3 [L]
</IfModule>
I see "Page not found" error as the browser goes to: https://www.mycompany.com/myDir/myFile.2013103000.html
Any idea what could be happening?
What can I do to trouble shoot?
Sitting at the webpage with the link, if I change .htaccess to this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+) https://www.mycompany.com/myDir/myFile.html [L]
</IfModule>
and then click the link it works (but obviously this just for troubleshooting).
UPDATE
Here's the complete .htaccess file in case something following the above can be identified as the problem:
# attempt to implement version control with cachebusting
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(html)$ $1.$3 [L]
</IfModule>
# Pruning irrelevant parts (Phil)
# force SSL and www
RewriteCond %{HTTP_HOST} ^mycompany\.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.mycompany.com/$1 [R=301,L]
# Redirect index.html to a specific subfolder;
Redirect permanent /index.html https://www.mycompany.com/home/
# enable pretty url
<IfModule mod_rewrite.c>
RewriteBase /home/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
I'd remove that last block and put it in a separate .htaccess file in your /home directory, eg
# /home/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
# not sure about the next 3 lines though
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>

htaccess to rewrite wordpress subdirectory with permalinks to root

I have a wordpress site installed in the directory "wp". I want to keep it in that folder for maintenance purposes. Wordpress gives the option to create a htaccess for permalinks. You can see that code (which works) below.
What I want is a rewriterule so - to visitors - the site appears to be in the root. I've to change the rewritebase, but that didn't work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
1) in your dashboard, go to settings -> general and make sure
a) wordpress directory -> http://mydomain.com/wp
b) site address -> http://mydomain.com
2) move your index.php from subdirectory to the root (MOVE, don't just copy)
3) edit your index.php to read
/** Loads the WordPress Environment and Template */
require('./wp/wp-blog-header.php');
where "wp" is your subdirectory
4) delete any .htaccess file in the subdirectory
5) add this to your .htaccess in the root
# 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
Under this setup, your wordpress installation will be located in /wp/ directory. Visitors will visit your site using http://mydomain.com. Good luck.
What would you think of that :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /wp/index.php [L]
RewriteCond %{REQUEST_URI} !^/wp/.*$
RewriteRule ^(.*)$ /wp/$1 [L]
You rewrite all non existing things to /wp/index.php, and all non /wp/ file to a /wp/ equivalent file. So if you call index.php it's in fact /wp/index.php
For a site with two WordPress blogs, one at the site root, and one in a subfolder, i.e. https://example.com/ and https://example.com/otherblog/, here's what i did
<Directory /data/sites/example.com/otherblog>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /otherblog/index.php [L]
</IfModule>
</Directory>
<Directory /data/sites/example.com>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</Directory>