Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to edit .htaccess file to make JWT plugin work? #104

Closed
max8hine opened this issue Nov 17, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@max8hine
Copy link

commented Nov 17, 2017

Hi, I am using WordPress jwt API, but it needs to edit the .htaccess
What's the location to do it?

@carrodher

This comment has been minimized.

Copy link
Member

commented Nov 17, 2017

Hi,

Once inside the container using the terminal, you can install your favorite text editor, for example

install_packages nano

You can find the htaccess file running a command like find / -type f -regextype sed -regex ".*htaccess.*"

root@796940d932fa:/# find / -type f -regextype sed -regex ".*htaccess.*"
/bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf
/bitnami/wordpress/wp-content/plugins/akismet/.htaccess
/bitnami/wordpress/wp-content/plugins/all-in-one-wp-migration/lib/vendor/servmask/filesystem/class-ai1wm-file-htaccess.php
/opt/bitnami/apache/manual/howto/htaccess.html.ko.euc-kr
/opt/bitnami/apache/manual/howto/htaccess.html.es
/opt/bitnami/apache/manual/howto/htaccess.html.fr
/opt/bitnami/apache/manual/howto/htaccess.html.ja.utf8
/opt/bitnami/apache/manual/howto/htaccess.html.en
/opt/bitnami/apache/manual/howto/htaccess.html.pt-br
/opt/bitnami/apache/manual/howto/htaccess.html
/opt/bitnami/apache/manual/rewrite/htaccess.html.fr
/opt/bitnami/apache/manual/rewrite/htaccess.html.en
/opt/bitnami/apache/manual/rewrite/htaccess.html

Discarding manual and plugin files, you should edit /bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf:

nano /bitnami/apache/conf/vhosts/htaccess/wordpress-htaccess.conf
@max8hine

This comment has been minimized.

Copy link
Author

commented Nov 17, 2017

@carrodher Thank you for the very detailed explanation.

I found the wordpress-htaccess.conf file in my editor.

the following problem is that I need to add this code into the regular .htaccess.conf
but don't know how to do in the wordpress-htaccess.conf.

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	RewriteRule ^index\.php$ - [L]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /index.php [L]
	RewriteCond %{HTTP:Authorization} ^(.*)
	RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>

I believe the rewrite_module is enabled on line 157 of httpd.conf.

I guess I have the trouble at <Directory "url_???">
because If I want to add the <ifModule true> to make something work,
I need to tell the WP where to add.

BTW, I am trying to make the plugin of JWT Authentication for WP REST API work in this image

@silviofdez

This comment has been minimized.

Copy link

commented Nov 21, 2017

Following JWT Authentication for WP Rest API I can make it works.

Here are the steps I follow:
1 - Uninstall JWT JWT Authentication for WP Rest API from the WP plugins dashboard.
2 - Edit the file wp-config.conf and add the following lines:

//JWT params
define('JWT_AUTH_SECRET_KEY', 'y-1|H2j|5-~+ed)-wo_bCuSB.**0=3uBHX+RXBY!|$Tat#B6l=L#H`~X#-uz<1R5');
define('JWT_AUTH_CORS_ENABLE', true);

3 - Edit the file wordpress-htaccess.conf and add these lines (at the root level, outside the group)

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

4 - Deactivate and activate again JWT from the WP plugins dashboard.
5 - Now your system is ready to use JWT, you can get your token making a POST request to YOURIP/jwt-auth/v1/token?username=user&password=bitnami

From now you can use your token to authenticate following plugin instructions.

@max8hine max8hine changed the title how to edit .htaccess file? How to edit .htaccess file to make JWT plugin work? Nov 21, 2017

@max8hine

This comment has been minimized.

Copy link
Author

commented Nov 21, 2017

@silviofdez It works!

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

just add those lines in the root level, without any group!
It works after turn down my docker-compose and up it!

I edited the title of this issue, in case others have the same problem.

Thank you =)

@carrodher

This comment has been minimized.

Copy link
Member

commented Nov 22, 2017

We are glad that you were able to fix the issue and solve your question. We will close this issue, if you have any other questions, please do not hesitate to let us know.

@carrodher carrodher closed this Nov 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.