我想从网址中删除文件名和扩展名,我有一个目录(博客),其中有两个文件(Main_blogs.php)和(Blog.php)
localhost / SikandarIqbal.net / blogs /
当我打开目录“博客”中的Main_blog.php时,我得到了上面的网址,我可以通过这个htaccess文件获得:
DirectorySlash Off
DirectoryIndex disabled
RewriteEngine on
# prevent direct access to PHP files
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php$ - [R=404,L]
# rewrite requests for a directory to index.php
RewriteCond %{REQUEST_FILENAME}/Main_blogs.php -f
RewriteRule ^.*$ $0/Main_blogs.php [L]
当我从Main_blog.php打开特定博客时,网址变为
本地主机/ Sikandariqbal.net /博客/ blog.php的/ MY-博客名称
我真正想要的是像什么
本地主机/ Sikandariqbal.net /博客/ MY-博客名称
删除/ Blogs /和/ My-Blog-name
请帮忙!
感谢
答案 0 :(得分:0)
您需要一个额外的规则:
DirectorySlash Off
DirectoryIndex disabled
RewriteEngine on
# prevent direct access to PHP files
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php$ - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Blogs)/page/(\d+)?$ $1/?pn=$2 [L,NC,QSA]
# rewrite requests for a Blogs/Blog.php/<url>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Blogs)/([\w-]+)/?$ $1/Blog.php/$2 [L,NC]
# rewrite requests for a directory to Main_blogs.php
RewriteCond %{REQUEST_FILENAME}/Main_blogs.php -f
RewriteRule ^.*$ $0/Main_blogs.php [L]