简体   繁体   中英

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 phpmyadmin or 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~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM