使用htaccess的在PHP URL重写 [英] URL rewrite using htaccess in PHP

查看:190
本文介绍了使用htaccess的在PHP URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让使用htaccess的重写规则SEO友好的URL。请找到它们下面。

I am trying to get SEO friendly urls using htaccess rewrite rules. Please find them below.

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^brands brands.php [NC,L]

RewriteRule ^facebook/([0-9]+) facebook.php?fb_page_id=$1 [NC,L]
RewriteRule ^twitter/([0-9a-zA-Z]+) twitter.php?twitter_screen_name=$1 [NC,L]

我在本地主机验证所有这些工作正常的链接在XAMPP环境。但是,当我主持他们的远程服务器操作系统的CentOS和虚拟主机配置的子域。

I verified in my localhost all the link they are working fine in xampp environment. But when i hosted them in remote server with OS centos and virtualhost configuration for a subdomain.

我原来的网址就会像下面。

My Original urls will be like below.

base_url/facebook.php/fb_page_name=7up+India

base_url/twitter.php/twitter_screen_name=7up+India

该规则不工作,并给予内部服务器错误,像下面。

The rules are not working and giving internal server error like below.

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
enter code here

那么我验证的远程服务器中包含一个主网站简单htaccess的重定向规则。它完美地工作。我无法找到问题出在哪里。

So i verified in remote server with simple htaccess redirection rules like below one to main site. It worked perfectly. I am not able to find what went wrong.

Redirect 301 / http://example.com/

我原来的URL格式是这样的 http://example.com/facebook.php/fb_page_name=7up+India 在网页中调用URL格式是这样的的href =/ Facebook的/七喜+印度 最终期待的URL是这样的 http://example.com/facebook/7up+India

My Original URL format was this http://example.com/facebook.php/fb_page_name=7up+India Calling URL format in pages was this href='/facebook/7up+India' Final expecting url was this http://example.com/facebook/7up+India

推荐答案

让你的规则是这样的:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteRule ^brands brands.php [NC,L]

RewriteCond %{THE_REQUEST} \s/+facebook\.php\?fb_page_id=([^\s&]+) [NC]
RewriteRule ^ facebook/%1? [R=302,L,NE]

RewriteCond %{THE_REQUEST} \s/+twitter\.php\?twitter_screen_name=([^\s&]+) [NC]
RewriteRule ^ twitter/%1? [R=302,L,NE]

RewriteRule ^facebook/([^/]+)/?$ facebook.php?fb_page_id=$1 [NC,L,QSA]
RewriteRule ^twitter/([^/]+)/?$ twitter.php?twitter_screen_name=$1 [NC,L,QSA]

这篇关于使用htaccess的在PHP URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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