apache - Problem with RewriteRule rewriting url
PHP中文网
PHP中文网 2017-05-16 17:00:32
0
2
574

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中文网

认证高级PHP讲师

reply all(2)
習慣沉默

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

伊谢尔伦

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...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!