htaccess with wordpress inside subdirectory - php

i've a simple question but i cant find and answer for that:
i have in my site-root folder 3 subdirectory, in the first one i have a wordpress site, in the second and in the third two other sites but only for testing like this:
domain.com/wordpress/
domain.com/test1/
domain.com/test2/
Now i want when the user goes on the site to redirect him on my wordpress site but also when i want to access the other sites i directly put the correct address and go.
Right now i have the code down below but, when i try to connect to other folder he redirect me to the 404 wordpress page. How should i edit it to make it works?
I also want if its possible when i go on wordpress to not show the subdirectory in the url but only the domain:
NOT -> domain.com/wordpress/index.php
BUT -> domain.com/index.php
RewriteEngine On #created by aruba do not touch this file!
RewriteCond %{REQUEST_URI} !(.*)wordpress
RewriteRule ^(.*)$ wordpress/$1 [L]

Related

Stop Wordpress on Subdomain

I have a website (http://alvarezpatrick.com) that uses wordpress. I have set up a subdomain (portfolio.alvarezpatrick.com) which I want to use to show example projects, etc. and which I would like not to be part of wordpress. However, if you go to http://portfolio.alvarezpatrick.com it seems to redirect you to http://alvarezpatrick.com, and if you go to http://alvarezpatrick.com/portfolio_html/index.php it seems to say it isn't found.
From looking around I've seen that it should work if I do the following, but unfortunately it does not:
Edit the .htaccess in the main public folder by adding:
RewriteCond %{http_host} ^(www\.)?alvarezpatrick\.com$ [nc]
Create a .htaccess in the portfolio.alvarezpatrick.com domain root folder "portfolio_html" with the following single line of code: RewriteEngine Off
Your main website is on public_html. To avoid using the wordpress on your sub-domain you can point the sub-domain outside the public_html.
For example:
/portfolio/ --- portfolio.example.com
/public_html/ --- example.com

2 different Wordpress blogs with same URL on Magento multisite

I have a magento multisite with 2 tld.
a) domain-a.com (Wordpress files located in /blog)
b) domain-b.com (Wordpress files located in /blog_b)
On domain-a.com i have a Wordpress blog installed on domain-a.com/blog
I want to do that same thing on domain-b.com/blog, but it should show other Wordpress installation located in /blog_b
When i change website address in Wordpress located in /blog_b to /blog, it shows the Wordpress installation in /blog and not /blog_b
I do not want to run Wordpress Multisite, nor do i want to integrate Wordpress and Magento.
I guess i need to make a change in .htaccess so when i visit domain-b.com/blog it shows Wordpress install located in /blog_b?
Hope you understand what i am trying to archieve here.
To keep it simple you could place an index page in /blog, with a frame or something that redirects to /blog_b. But with .htaccess you can do the following:
# Redirect /blog to /blog_b
Redirect 301 /blog http://domain-b.com/blog_b
EDIT:
Right, I did not think about normal requests to domain-a.com/blog. I am not sure, but I think this could work. It will check if the requested domain is domain-b.com, and if the requested subfolder is /blog. If so, forward to /blog_b. Just a suggestion that might not work, I can't test this right now, sorry.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain-b.com
RewriteCond %{REQUEST_URI} ^/blog
Rewriterule ^(.*)$ /blog_b [L]
I solved this by installing a Wordpress multisite instead. I can not say if your answer worked, because i went ahead with other solution first.
Thanks anyway :)

rewrite url using mod_rewrite and remove sub directories

I am currently building a website and it hasn't gone online, I am using wamp server 2.4. I need to remove the sub directories so as to not let out the structure of my directories, I have a test site with the following folders: includes and sub.
The links to be accessed are in sub so if the user clicks on a link that goes to sub/link.php, the url shows localhost/sub/link.php..I would like it to show localhost/test/link/ without the sub showing. So far I have googled mod_rewrite in Apache, learnt about it but still unable to remove sub-directory. All I have achieved is to remove the file extension(.php).
I have searched here on Stack Overflow but the answers are not helping maybe because they use online hosted websites. The link.php has no variables, it's a simple php file that could echo stuff but it's not using any GET/POST variables.
This is the html code, i have intentionally written one 't' in 'http'..though in the code it is two..
Link
RewriteEngine On
RewriteRule ^sub/(.*)$ /$1 [L,R=301]
Take a look at this site, it's hosted on wordpress and every link that you go to is shown without any subdirectories, it's just got one trailing slash after the url, is it possible to achieve that on apache?
http://www.afdar.com
Try this in your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/test/sub/
RewriteRule ^test/(.*)$ /test/sub/$1 [QSA,L]
It will rewrite URLs:
http://localhost/test/sub/link.php to http://localhost/test/link.php
http://localhost/test/sub/another.php to http://localhost/test/another.php

Wordpress url rewrite on subdirectory

I have a wordpress install which has only two custom post types ( blog and howto ).
The blog is located in a directory inside root folder where also are few html pages, like this :
To access a certain custom post type from html files i have an href to wp/blog and another one to wp/howto.
The problem is that i want to jump that wp so my url will be like localhost/blog instead localhost/wp/blog.
I tried with
RewriteEngine On
RewriteRule blog/ /wp/blog/
RewriteRule howto/ /wp/howto/
in .htaccess from root directory, it shows me the blog template, but only 404 page error and i have no idea what should i modify to get the wordpress posts.
PS : Sorry for my english and for my blurry message, deadline's coming and i have no idea what should i do to skip that folder.
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.
If you want to have a good read-up on everything so you know exactly what you're doing, read this https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
If i understand you correctly - all the wordpress system files are inside the "wp" folder.
if that is the case all you need to do is to drag them out to the main folder and the problem would be fixed by itself.
As far as the post types (blog/howto) if those are post types inside the wordpress system the are not effected by real folders but by something call Wildcard DNS - which is a method of linking url's to content by values inside the url. this means that the folder does not have to exist inside the server but just in the system.
For solving your issue i recommend to just, as i said before - drag all the files from inside the folder "wp" - outside of it.
And after that you will need to log in to the database with phpmyadminor any other client you have and go to:
A) choose wp_options
B) Look option_name for siteurl and remove the "wp" from the url. (if it's http://sample.com/wp change it to http://sample.com)
C) Look option_name for home and do the same.
Edit:
Try this:
in your root directory (the parent of "wp"), open the .htaccess file and add inside mod_rewrite.c:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
RewriteRule ^(/)?$ wp [L]
change the YourDomain.com to your real domain.
this should work :)
source: ~here~
im looking for a solution just like this. People keep on going around the question. What you want is for the custom posts to look like they come from the route mysite.com/todo/have-a-nice-day mysite.com/blog/todo/instead of mysite.com/blog/

.htaccess WP-admin url twice

I am unable to access my WordPress site URL, it redirects like
http://www.mydomain.net/wp-login.php?redirect_to=http%3A%2F%2Fmydomain.net%2Fmydomain.net%2Fwp-admin%2F&reauth=1
but it shoud redirect to
http://www.mydomain.net/wp-login.php?redirect_to=http%3A%2F%2Fmydomain.net%2Fwp-admin%2F&reauth=1
I believe the problem is with .htaccess file as I am rewriting the path of folder like
public_html/mydomain.net
instead of public_html as this domain is primary domain of cPanel but to avoid confusing, I created a directory and rewriting path using .htaccess.
There is nothing wrong with WordPress. In settings>general both the URLs set to mydomain.net
.htaccess code is Placed in Public_HTML
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.net$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.net$
RewriteCond %{REQUEST_URI} !mydomain.net/
RewriteRule (.*) /mydomain.net/$1 [L]
I had a similar problem after changing the root directory of my blog (before migration) and trying to coming back... Changing the data in my DB was not working for me.
I still did not figure out why but I had a "page not found" when I tried to access categories, tags,... and even on the home page. Links to articles worked correcly and the administration page was not accessible (wp-admin rewritten twice in the url).
These actions solved my problem:
Edit the wp-config.php file.
After the "define" statements (just before the comment line that says "That's all, stop editing!"), insert a new line, and type:
define('RELOCATE',true);
Save your wp-config.php file.
Open a web browser and manually point it to wp-login.php on the new server.
I had to change the value of the root directory in the administration page (after these actions gave me back the access to it).
Check http://codex.wordpress.org/Changing_The_Site_URL#Relocate_method for more info.

Categories