【问题标题】:.htaccess Pretty URL rewrite inside a folder.htaccess 在文件夹内重写漂亮的 URL
【发布时间】:2015-10-14 00:45:36
【问题描述】:

我正在尝试将我的一个网址重写为漂亮的网址,但我似乎无法弄清楚。这是我尝试过的

当前文件夹布局

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

在 .htaccess 里面我放了这段代码

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

我的目标是转这个网址

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

进入这个网址

http://example.com/instagram/test1234

但是,当我转到浏览器中的第二个 url 时,它会给出 404 not found 错误。关于如何解决这个问题的任何想法?

【问题讨论】:

  • 你试过RewriteRule ^instagram/([^/]*)$ /instagram/index.php?username=$1 [L]我只是想你可能想明确地给它 index.php 文件,因为它无论如何都不会显示
  • 当我尝试收到 500 内部服务器错误

标签: php apache .htaccess mod-rewrite friendly-url


【解决方案1】:

将此代码放入/instagram/.htaccess:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /instagram/

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

【讨论】:

  • 完美运行。谢谢!
  • 当这个人 ^ 回答一个 .htaccess / mod_rewrite 问题时,你可以 99% 确定它是正确的 - 似乎也经常忍着我 ;)
  • 非常感谢您的客气话@CD001
猜你喜欢
  • 1970-01-01
  • 2016-01-25
  • 1970-01-01
  • 2012-03-04
  • 1970-01-01
  • 1970-01-01
  • 2012-11-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多