【发布时间】:2021-09-16 16:27:05
【问题描述】:
我正在尝试重写此 URL:http://localhost/mysite/admin/edit-post.php?id=12
预期的输出 URL:http://localhost/mysite/admin/edit/12
mysite 是我的根文件夹
admin 是我的根文件夹中的子文件夹
edit-post.php 文件在我的子文件夹中
我的 htaccess 代码:
# 404 page
ErrorDocument 404 http://localhost/mysite/404.php
RewriteEngine On
RewriteBase /mysite/
# Extension Removal
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# URL Rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# This Rule is for the file which i have it in my root folder, It's working
RewriteRule ^posts/(.+)$ post.php?id=$1 [L]
# And I'm tring the same but it's not working.
RewriteRule ^edit/(.+)$ edit-post.php?id=$1 [L]
我的php代码
<a href="edit/<?php echo $post_detail['id']; ?>">Edit Post</a>
【问题讨论】:
标签: .htaccess redirect mod-rewrite url-rewriting friendly-url