繁体   English   中英

如何使用 .HTACCESS 和 PHP 重写 url

[英]how to rewrite url using .HTACCESS and PHP

以下 htacces 代码仅重定向到第一个链接,不适用于以下两个链接 .htaccess 文件

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

RewriteRule ^([-\w]+)$ stateProperty.php?state_name=$1 [NC,L]
RewriteRule ^([-\w]+)$ propertyTypes.php?property_types_name=$1 [NC,L]
RewriteRule ^([-\w]+)$ propertyStatus.php?property_status_name=$1 [NC,L]

php 代码

<a href="<?php echo str_replace(' ', '-', strtolower($countStateProjects['state_name'])) ?>" class="py-0 d-block">Properties In <?php echo $countStateProjects['state_name'];?>
<a href="<?php echo str_replace(' ', '-', $propertyTypes['property_types_name']) ?>" class="py-0 d-block"><?php echo $propertyTypes['property_types_name']; ?> for Sale in India/a>
<a href="<?php echo str_replace(' ', '-', $propertyStatus['property_status_name']) ?>" class="py-0 d-block"><?php echo $propertyStatus['property_status_name']; ?> Projects for Sale in India</a>

以下 htacces 代码仅重定向到第一个链接,不适用于以下两个链接 .htaccess 文件

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

RewriteRule ^([-\w]+)$ stateProperty.php?state_name=$1 [NC,L]
RewriteRule ^([-\w]+)$ propertyTypes.php?property_types_name=$1 [NC,L]
RewriteRule ^([-\w]+)$ propertyStatus.php?property_status_name=$1 [NC,L]

php 代码

<a href="<?php echo str_replace(' ', '-', strtolower($countStateProjects['state_name'])) ?>" class="py-0 d-block">Properties In <?php echo $countStateProjects['state_name'];?>
<a href="<?php echo str_replace(' ', '-', $propertyTypes['property_types_name']) ?>" class="py-0 d-block"><?php echo $propertyTypes['property_types_name']; ?> for Sale in India/a>
<a href="<?php echo str_replace(' ', '-', $propertyStatus['property_status_name']) ?>" class="py-0 d-block"><?php echo $propertyStatus['property_status_name']; ?> Projects for Sale in India</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM