如何使用 .htaccess 创建干净的 url [英] How to create clean url using .htaccess

查看:19
本文介绍了如何使用 .htaccess 创建干净的 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 .htaac​​cess 代码.

This is my .htaaccess code.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ movie.php?name=$1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.in$
RewriteRule ^/?$ "http\:\/\/example\.in" [R=301,L]
ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None

我的网站需要干净的网址.我参考了很多教程和论坛并创建了上面的代码.但不工作.. 几乎我正在与代码作斗争.我不清楚干净的 url 概念.有没有我要在我的 php 页面上写的代码.

I need clean url for my website. I've referred lots of tutorials and forums and created the above code. But not working.. Almost I'm fighting with code. I dont understand the clean url concept clearly. Is there any codings I ve to write on my php page.

<a href='movie.php?name=titanic'> Titanic </a>

我的 index.php 文件中有这个链接.

I've this link in my index.php file.

我想要example.in/movie/titanic,同时点击链接泰坦尼克号.

I want example.in/movie/titanic while click the link Titanic.

我还想通过 $_[request] 获取值.

Also I want to get the value by $_[request].

我到底要做什么.请不要让这个问题重复,我已经搜索了很多,但没有清楚地了解这个概念.请帮帮我.

What exactly I've to do. Please dont make this question as duplicate, I've searched a lot and didn't got the concept clearly. Please help me out.

谢谢

推荐答案

用这个替换你的代码:

ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+movie\.php\?name=([^\s&]+) [NC]
RewriteRule ^ movie/%1? [R=301,L]

RewriteRule ^movie/([^/]+)/?$ movie.php?name=$1 [L,QSA]

这篇关于如何使用 .htaccess 创建干净的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆