Home  >  Q&A  >  body text

apache - Problem with RewriteRule rewriting url

Wordpress is installed in the blog folder in the root directory, so the address becomes http://mydomain.com/blog
Log path http://mydomain.com/blog/sample-post/
Can I use RewriteRule to change the path of wordpress to http://mydomain.com/sample-post and hide the blog?
(sample-post is not fixed, it is the name of each log, variable)
After reading htaccess for a long time, I didn’t understand how to write it.
I would also like to ask a questionRewriteRule . /index.php [L]The meaning of this sentence
Some people will have an additional index.php in the path after installing wordpress, so they need to add this sentence Remove index.php
Syntax for rewriting rules:

RewriteRule Pattern Substitution [flags]

An explanation I saw is this:

Pattern is a perl-compatible regular expression that acts on the current URL.
Substitution in the rewrite rule is the string used to replace (or replace) when the original URL matches Pattern.

Then this is not using index.php to replace any character (I am not sure what this pattern means, doesn't the '.' in the regular expression represent any single character)?

Please explain, thank you~

PHP中文网PHP中文网2713 days ago582

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 17:02:32

    rewriterule ^/blog/([\/]+) /$1 [L]

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 17:02:32

    Solve it yourself...

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ blog/ [QSA,PT,L]
    

    Although it can be accessed normally if you remove the blog field in the URL, if you jump through the link in the page, the URL still has its own blog. Forget it, I'll move the directory...

    reply
    0
  • Cancelreply