如何创建pretty的网址 [英] how to create pretty urls

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

问题描述

我有我的网站像这样的URL - <$c$c>http://www.mydomain.com/profiles/centers/index.php?$c$c=2507&name=Tharanga+Higher+Educational+Institute#page=art-section

I have a URL from my website like this - http://www.mydomain.com/profiles/centers/index.php?code=2507&name=Tharanga+Higher+Educational+Institute#page=art-section

我需要显示上述网址为友好的URL在浏览器的地址栏时,将上述页面。

I need to display above url as friendly url on my browser's address bar when it going to above page.

我期待网址是这样的 -

My expecting url something like this -

http://mydomain.com/centers/Tharanga-Higher-Educational-Institute#page=art-section

这code至今在我的.htaccess文件

This code so far in my .htaccess file

# Enable Rewriting 
RewriteEngine on 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/centers/index.php\?code=([0-9]+)&name=([^&]+)&?([^\ ]+)
RewriteRule ^profiles/centers/index\.php /%1/?%2 [R=301,L,NE]

但是,这code是不是为我工作。希望有人可以帮助我。 谢谢。

But this code is not working for me. hope someone will help me out. Thank you.

推荐答案

替换您的code这一点:

Replace your code with this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+profiles/centers/index\.php\?code=([^&]+)&name=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/([^/]+)/?$ /profiles/centers/index.php?code=$1&name=$2 [L,NC,QSA,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpe?g|gif|png)$ /profiles/centers/%{REQUEST_URI} [NC,L,R=302]

一旦你验证它是否工作正常,更换 R = 302 R = 301 。避免使用 R = 301 (永久重定向),而测试你的mod_rewrite规则。

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

这篇关于如何创建pretty的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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