.htaccess ApacheHTAccess-如何重写URL以包含页面';广告名称的价值?
我有一台运行CENTOS 6.9 x86_64 xen hvm、cPanel&WHM 64.0(build 15)、Apache 2.4.25和PHP5.6.30的专用服务器 我的网站的.htaccess文件当前包括以下内容,并按预期工作:.htaccess ApacheHTAccess-如何重写URL以包含页面';广告名称的价值?,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一台运行CENTOS 6.9 x86_64 xen hvm、cPanel&WHM 64.0(build 15)、Apache 2.4.25和PHP5.6.30的专用服务器 我的网站的.htaccess文件当前包括以下内容,并按预期工作: RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
ErrorDocument 404 /404.php
由于我对mod_rewrite和PHP缺乏经验,我需要以下方面的帮助:
我的网站包含不同型号的个人资料页面。
当前模型配置文件URL的示例如下所示:
我希望URL改为重新编写为:
为了显示(在profile.php页面中)模型的广告名称,我有以下代码:
<?php require_once('cms/includes/init_files.php');?>
<?php
$id = getParam('id');
$query_string = "SELECT * from profiles where id='$id'";
$query = $db->query($query_string);
$data = $db->fetch_assoc($query);
?>
您可以添加如下所示的重写规则
这将把这里的profile/123/model ad name
重写为profile.php?id=123
,以使您的url运行良好。此规则仅适用于数字ID,此处的型号广告名称将被忽略
这是非常基本的URL重写。你可以继续读下去,将来自己做
不需要编辑您的页面,除非所有指向配置文件的链接都必须更新为新的URL
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# This rewrites 'profile/123/model-ad-name-here' to 'profile.php?id=123'
RewriteRule ^profile/([0-9]+) profile.php?$1 [L]
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# This rewrites 'profile/123/model-ad-name-here' to 'profile.php?id=123'
RewriteRule ^profile/([0-9]+) profile.php?$1 [L]