简体   繁体   English

.htaccess在文件夹中重写漂亮的URL

[英].htaccess Pretty URL rewrite inside a folder

I am trying to rewrite one of my urls to pretty urls but I can't seem to figure it out. 我试图将我的一个网址重写为漂亮的网址,但我似乎无法弄明白。 Here is what I've tried 这是我尝试过的

Current folder layout 当前文件夹布局

-index.php
-/instagram
    -index.php
    -.htaccess

Inside the .htaccess I have put this code 在.htaccess里面我已经放了这个代码

RewriteEngine On
RewriteRule ^instagram/([^/]*)$ /instagram/?username=$1 [L]

My goal is to turn this url 我的目标是打开这个网址

http://example.com/instagram/?username=test1234

into this url 进入这个网址

http://example.com/instagram/test1234

However, when I go to the second url in my browser it gives a 404 not found error. 但是,当我在浏览器中转到第二个URL时,它会发出404未找到的错误。 Any idea on how to fix this? 有关如何解决此问题的任何想法?

Place this code inside /instagram/.htaccess : 将此代码放在/instagram/.htaccess

DirectoryIndex index.php
RewriteEngine On
RewriteBase /instagram/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?username=$1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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