I have a wordpress site installed on a domain, inside a subfolder. Now my client wants to show it as the default page, but I don't know how to do it without reinstalling WP to the root directory of the server.
I simply want to rewrite to URL of mysite.com/wp to mysite.com, and other subfolderls like mysite.com/wp/a-wordpress-page to mysite.com/a-wordpress-page
What I've tried so far:
Placed an index.php to the root with header redirect, but it will rewrite the URL to /wp
Including the /wp/index.php to the main index.php. It works when you open the page, but after following any link on the site, the /wp/ part will show up again.
Tried some RewriteRules in .htaccess but can't figure out how to do it correctly.
So what is the easiest solution to do it with .htaccess or PHP?
Related
I've recently learned that I'm unable to use the .htaccess file to redirect and rewrite url's on an NGINX server. I'm in the process of migrating a 20,000 page .html website to wordpress, and must preserve the permalink structure and add redirects to maintain the SEO.
All I am trying to accomplish are two things:
Add a 301 redirect to .html pages that will point them to their .php counterparts
Remove the '/public_html/' folder from the page URL
www.website.com/public_html/[affiliate] => www.website.com/[affiliate]
I have been able to implement the 301 redirects via plugin for now, however I'm unsure how to go about removing the folder from the URL. I could place the affiliate folders in the root directory and not have to do this, but it will clutter up my workspace immensely.
This is my current attempt at rewriting the url (in site.conf.hbs --- is this the correct file?)
#
# Rewrite public_html out of url when visiting affiliate pages
#
location /public_html
{
rewrite ^(/public_html/.*)/(\w+).php /$2.php last;
}
Any help is much appreciated! The php redirect is working via plugin for now, but I'd like to just add it as a rule to get rid of the plugin if possible.
Thanks!
I have my folders in public_html like this,
/ - root public html for example.com [has wordpress in it]
/a/ - this has another wordpress installed and a.example.com should be pointed to this directory
/b/ - again wordpress for b.example.com
I tried this code,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^a\.example\.com$
RewriteCond %{REQUEST_URI} !^/a/
RewriteRule (.*) /a/$1
but it doesn't work. I use VestaCP control panel and don't want to add site for each subdomain instead have it all under the same root directory.
I also noticed that going to a 404 page like example.com/a/somenotfoundpage will show me the 404 page of the root wordpress installation and not /a/ installation
How can it be fixed inside .htaccess ? /a/ and /b/ are both multi site installation each and / is normal installation
the url for the /a/ and /b/ are set to a.example and b.example in wordpress settings
EDIT
VestaCP is set to redirect *.example.com to example.com. (I have used it as an aliases when adding the site, and visiting a.example.com shows me example.com content without the address changing in the address bar)
In your wp-config.php file, there's a line that says Subdomains and it's set to 'false' right now. Change it to true and your site will flip over.
Now that said... You may want to consider .htaccess redirecting the old URLs to the new ones. But it should work just that easily.
I have a wordpress site with complete URL as:
mydomain.com/wp_myfolder/index.php
but after WordPress rewriting I access my site as mydomain.com Now I want to place another project in another folder on same domain but I am facing issues
I want to access my new project as this but it is not working
mydomain.com/project/mypage.php
instead it is opening as
mydomain.com/wp_myfolder/project/mypage.php
it want to remove wp_myfolder from url
Try to add this rewrite rule in your .htaccess.
RewriteRule ^project/(.*)$ /wp_myfolder/project/$1 [L]
Ok, I am very new to web development, so excuse that. I set up my webserver using a Linode Stackscript (LAMP). However, my webpage doesn't display my actual index.php file, instead, it displays http://www.imgbomb.com/i/?lBqKe. Why is this? My index.php is inside my www. When I type /index.php after the url, I get a the page you are looking for is not found.
You should add DirectoryIndex index.php to your .htaccess file or webserver configuration file.
I have a very basic two-page website: the home page, and an about page. What I'm trying to do is use htaccess to rewrite the URLs so that the appear as:
domain.com/ (for the home page)
domain.com/about (for the about page)
In the actual folder structure of the site, the homepage is /index.php and the about page is /about.php (both appear in root).
I've been doing research into using alias but unfortunately my hosting (Dreamhost) doesn't allow access to httpd.config so that's out the window and I'm left with using rewrite rules in the htaccess file.
Since the index.php file will appear in the domain root (http://domain.com/) automatically, I've so far managed to make the about page appear correctly at domain.com/about using these lines:
RewriteEngine On
RewriteRule ^about$ /about.php
I'm also using 301 redirects so that for example, domain.com/about/ (with the trailing slash) also directs back to the /about URL like this:
Redirect 301 /about/ http://domain.com/about
This works great.
However the index.php and about.php files still also show if you go to the correct URL within your browser (eg: domain.com/about.php) so as a result the search engines are seeing (and indexing) two versions of each page! I've set up the correct canonical metadata within each page but this doesn't seem to have had any effect (the canonical metadata have been within the page markup ever since the site went live).
So how would I go about firstly doing a 'blind' rewrite (for want of a more technical term) for the two files so that the URLs look correct, but also effectivly 'block' direct access to the files - ensuring that if someone were to attempt to access the php files directly, the URL would still appear in the visitor's browser as the 'pretty' versions rather than the full file name and php extension?
Any advise would be hugely appreciated, I've been researching this for another couple of days now (I don't think there's anything quite the same as this anywhere on here already) and cannot for the life of me work this one out!
Check $_SERVER['REQUEST_URI'] in the PHP files. If that contains the filename (instead of the URI that you want), then do a 301 or 404 or whatever you want. Else serve the page as usual.
You can also do a
RewriteRule ^about.php - [L,gone]
or
RewriteRule ^about.php /about [L,R=301]
but this has to go before your other RewriteRules. It will send a 410 Gone or a 301 Moved Permanently response if the page is accessed via /about.php. See Apache Module mod_rewrite for the complete documentation of mod_rewrite.