简体   繁体   English

PHP URL重写并在Htacess中重定向

[英]Php url rewrite and redirect in htacess

I want to redirect my site to friendly. 我想将我的网站重定向到友好站点。 I have my website pull data from database and adress is /post?id=1 and i want to change it to /post/1 I already wrote the code for rewrite but i cant make sense from google research how to redirect to /post/1. 我有我的网站从数据库中提取数据,地址是/ post?id = 1,我想将其更改为/ post / 1,我已经编写了重写代码,但是我无法从Google Research中得知如何重定向到/ post / 1。

my code 我的代码

Options +FollowSymLinks
 RewriteEngine on
 RewriteRule ^post/([^/.]+)/?$ post.php?id=$1 [L]

Use: 采用:

Options +FollowSymLinks
RewriteEngine on

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+post\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /post/%1? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^post/([^/.]+)/?$ post.php?id=$1 [L,QSA,NC]

This one worked for me 这个为我工作

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ post.php?id=$1  [NC]

if you goto url /post/check1/ 如果您转到url / post / check1 /

the htaccess file internally call post?id=check1 htaccess文件内部调用post?id = check1

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

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