在核心php中自定义URL重写
我正在核心PHP中进行URL重写。我需要帮助 我的URL具有以下格式:在核心php中自定义URL重写,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我正在核心PHP中进行URL重写。我需要帮助 我的URL具有以下格式: http://xyz.in/index.php?view=wholesale&page=fcat&id=161 我想将其转换为: http://xyz.in/ABC 这里的页面和视图是用于获取特定页面的参数 ABC是类别名称,其类别ID在类别表中的值为161 我发现了许多与htaccess文件相关的解决方案,但它们对我不起作用,因为没有任何解决方案可以使用URL参数(类别ID)从数据库中检索值(类别名称
http://xyz.in/index.php?view=wholesale&page=fcat&id=161
我想将其转换为:
http://xyz.in/ABC
这里的页面
和视图
是用于获取特定页面的参数
ABC
是类别名称,其类别ID在类别表中的值为161
我发现了许多与
htaccess
文件相关的解决方案,但它们对我不起作用,因为没有任何解决方案可以使用URL参数(类别ID)从数据库中检索值(类别名称)。在.htaccess文件中添加重写规则,如下所示
Options +FollowSymlinks
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule index\.html index.php
Options -Indexes
RewriteCond %{HTTP_HOST} ^xyz\.in
RewriteRule ^(.*)$ https://www.xyz.in/$1 [R=permanent,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
#admin
//this is for single params
RewriteRule ^([A-Za-z0-9_-]+)/index.php$ ?page=ABC&category=$1 [L]
//If you need two params use this.
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/index.php$ ?page=ABC&category=$1&view=$2 [L]
您可以从该特定页面获取值
echo $_REQUEST['category'];
我希望您的解决方案足够了。像这样在.htaccess文件中添加重写规则
Options +FollowSymlinks
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule index\.html index.php
Options -Indexes
RewriteCond %{HTTP_HOST} ^xyz\.in
RewriteRule ^(.*)$ https://www.xyz.in/$1 [R=permanent,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
#admin
//this is for single params
RewriteRule ^([A-Za-z0-9_-]+)/index.php$ ?page=ABC&category=$1 [L]
//If you need two params use this.
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/index.php$ ?page=ABC&category=$1&view=$2 [L]
您可以从该特定页面获取值
echo $_REQUEST['category'];
我希望您的解决方案足够了。在您考虑执行此重写之前,您需要更新代码,以便能够使用类别名称检索信息。mod_rewrite无法为您执行此操作。..htaccess文件在此问题中不起作用?在您考虑执行此重写之前,您需要更新代码,以便能够使用类别名称检索信息。mod_rewrite无法为您执行此操作..htaccess文件在此问题中不起作用?