我有以下路径
root
--cp
----course-details.php
我需要以下网址
/category/course-name
course-details.php使用网址中的课程名称来查找课程并显示课程详情信息。
我尝试了不同的方式,但我无法做到。这就是我正在尝试的:
RewriteEngine On
RewriteBase /cp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/artes-escenicas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/ciencia-y-tecnologia/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/arte-y-diseno/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/deportes/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/idiomas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/academico/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/rutas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^/voluntariado/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
请任何帮助将不胜感激
答案 0 :(得分:0)
您必须在root .htaccess中使用此代码(级别高于/cp/
):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^artes-escenicas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^ciencia-y-tecnologia/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^arte-y-diseno/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^deportes/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^idiomas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^academico/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^rutas/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteRule ^voluntariado/([^/]+)/?$ cp/course-details.php?name=$1 [NC,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^([^.]+?)/?$ $1.php [L]
RewriteCond %{DOCUMENT_ROOT}/cp%{REQUEST_URI}\.php -f [NC]
RewriteRule ^([^.]+?)/?$ cp/$1.php [L]