Php 在.htaccess文件中针对mod_rewrite的querystring匹配模式时出现问题
我的项目中有4个URL,我正试图使用mod_rewrite进行翻译Php 在.htaccess文件中针对mod_rewrite的querystring匹配模式时出现问题,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我的项目中有4个URL,我正试图使用mod_rewrite进行翻译 hall/description_banquethall.php?hall_id=1 > hall/description_banquethall/1 hall/venues.php?city=hyderabad&city_value=1&lacality=malakpet&locality_value=82 > hall/venues/hyderabad/1/malakpet/82 ha
hall/description_banquethall.php?hall_id=1 > hall/description_banquethall/1
hall/venues.php?city=hyderabad&city_value=1&lacality=malakpet&locality_value=82 > hall/venues/hyderabad/1/malakpet/82
hall/hall_booking.php?hall_id=1&booking_date=2014-10-23&session=Morning > hall/hall_booking/1/2014-10-23/Morning
hall/booking_message.php?booking_id=10 > hall/booking_message/10
到目前为止,我在.htaccess中有以下内容适用于
hall/booking.php?hall_id=5&booking_date=2014-10-23&session=Morning
及
但不适用于上面列出的两个URL:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /hall/
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?city=([^&\s]+)&city_value=([^&\s]+)&locality=([^&\s]+)&locality_value=([^&\s]+) [NC]
RewriteRule ^ %1/%2/%3/%4/%5? [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ $1.php?city=$2&city_value=$3&locality=$4&locality_value=$5 [L,QSA]
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?hall_id=([^&\s]+)&booking_date=([^&\s]+)&session=([^&\s]+) [NC]
RewriteRule ^ %1/%2/%3/%4? [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/([^/]+)/([^/]+)/([^/]+)/?$ $1.php?hall_id=$2&booking_date=$3&session=$4 [L,QSA]
# To externally redirect /dir/foo.php?id=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?hall_id=([^&\s]+) [NC]
RewriteRule ^ %1/%2/? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?id=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?hall_id=$2 [L,QSA]
# To externally redirect /dir/foo.php?id=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?booking_id=([^&\s]+) [NC]
RewriteRule ^ %1/%2/? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?booking_id=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?booking_id=$2 [L,QSA]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\s [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
为什么不在.htaccess中使用这个呢
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule
^(.*)/?$ index.php?page=$1 [L]
</IfModule>
这有用吗?如果是,请投赞成票或给出一些反馈。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule
^(.*)/?$ index.php?page=$1 [L]
</IfModule>
# SELECT WHICH PAGE TO DISPLAY
function getPage($showPage) {
$modules = array(#never name the slugs as same as the php pages
'/sign-in/i' => 'register.php',
'/signout/i' => 'logout.php',
'/staff/i' => 'admin.php',
'/products/i' => 'blank.php',
);
foreach ($modules as $slug=>$phpmodule) {
if(preg_match($slug, $showPage)) {
return $phpmodule;
}
}
return 'blank.php';#in case module not found display 404 page
}
if (isset($_GET['page'])) {
require_once (getPage($_GET['page'])); #include the appropriate module file
}