我的网址是xyz.com/songs.php?lan=3&movie=198
,
我想展示xyz.com/moviename.html
,是否可以使用.htacces ..?请帮帮我
在我的.htaccess文件中使用 -
RewriteRule ^([^/.]+)/([^/.]+)$ songs.php?lan=$1&movie=$2 [QSA,L]
显示 - xyz.com/telugu/moviename
,但我想展示xyz.com/moviename.html
请帮助我,这对我来说是全新的
答案 0 :(得分:0)
在这种情况下,您可以执行CMS和框架所做的工作:
首先将所有请求重定向到.htaccess中的index.php:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw|xml|jpg|ajx))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
在此之后,所有请求都将重定向到index.php。例如DOMAIN / a.html和DOMAIN / a / b.html和......
此时$ _SERVER [&#39; REQUEST_URI&#39;]是您请求的地址,例如/a.html,您可以根据当前网址决定应显示哪些数据。
答案 1 :(得分:0)
如果你想要
xyz.com/moviename.html
然后你需要为每部电影写一条规则。即
# Catch xyz.com/123/the-movie-title
RewriteRule ^([0-9]+)/([^/.]+).html songs.php?lan=3&movie=$2
更简单的方法是在网址的某处包含movie_id:
#include <stdio.h>
#include <stdlib.h>
#include "int_stack.h"
struct int_stack *make_stack(int node_capacity) {
//malloc theseprintf("%d]", temp->contents[i]);
struct is_node *head;
struct int_stack *stacky;
head = malloc(sizeof(struct is_node));
stacky = malloc(sizeof(struct int_stack));
stacky->node_capacity = node_capacity;
head->contents = malloc(node_capacity * sizeof(int));
head->next_index = 0;
head->next = NULL;
stacky->size = 0;
stacky->head = head;
return stacky;
}
void free_stack(struct int_stack *stk) {
struct is_node *pointee;
pointee = stk->head;
while (stk->head->next != NULL) {
pointee = stk->head->next;
free(stk->head->contents);
free(stk->head);
stk->head = pointee;
}
free(stk->head->contents);
free(stk->head);
free(stk);
}
void reset_stack(struct int_stack *stk) {
struct is_node *temp;
while (stk->head->next != NULL) {
temp = stk->head->next;
free(stk->head->contents);
free(stk->head);
stk->head = temp;
}
stk->size = 0;
stk->head->contents = NULL;
stk->head->next_index = 0;
}
void print_stack(struct int_stack *stk) {
struct is_node *temp;
int i;
temp = stk->head;
i = temp->next_index - 1;
if (is_empty(stk) == 1) {
printf("(]");
}
while (i >= 0) {
if (i == temp->next_index - 1) {
if (i == stk->node_capacity - 1) {
if (i == 0) {
printf("[%d]",temp->contents[i]);
} else {
printf("[%d,",temp->contents[i]);
}
} else if (i == 0) {
printf("(%d]",temp->contents[i]);
} else {
printf("(%d,",temp->contents[i]);
}
} else {
if (i == 0) {
printf("%d]", temp->contents[i]);
} else {
printf("%d,",temp->contents[i]);
}
}
if (i == 0 && temp->next != NULL) {
temp = temp->next;
i = temp->next_index;
}
--i;
}
printf("\n");
}
int is_empty(struct int_stack *stk) {
if (stk->size == 0) {
return 1;
}
return 0;
}
void push(struct int_stack *stk, int v) {
stk->size++;
int i = stk->head->next_index;
if ((stk->size % stk->node_capacity == 1 && stk->size > stk->node_capacity) || (stk->node_capacity == 1)) {
struct is_node *new_head;
new_head = malloc(sizeof(struct is_node));
new_head->contents = malloc(sizeof(stk->node_capacity * sizeof(int)));
new_head->next = stk->head;
new_head->next_index = 1;
new_head->contents[0] = v;
stk->head = new_head;
} else {
stk->head->contents[i] = v;
stk->head->next_index = realloc();
}
}
int pop(struct int_stack *stk) {
int pop_val;
struct is_node *temp;
if (is_empty(stk) == 1) {
return -1;
} else if (stk->head->next_index == 1) {
pop_val = stk->head->contents[0];
stk->size = stk->size - 1;
stk->head->next_index = 0;
if (stk->head->next != NULL) {
temp = stk->head->next;
free(stk->head->contents);
free(stk->head);
stk->head = temp;
}
return pop_val;
} else {
pop_val = stk->head->contents[stk->head->next_index - 1];
stk->head->next_index = stk->head->next_index - 1;
stk->size = stk->size - 1;
return pop_val;
}
}
int top(struct int_stack *stk) {
if (is_empty(stk) != 1) {
return stk->head->contents[stk->head->next_index - 1];
}
return -1;
}
这种方式可以捕获所有电影而无需为每个电影制定特定规则。然后,您可以在代码中检查ID是否有效。您还可以获取电影标题并检查它是否与URL匹配,如果没有根据电影ID重定向到正确的电影标题。
答案 2 :(得分:0)
鉴于您的意见,我认为您应该尝试不同的方法。
更新.htaccess以通过单个文件(index.php)路由所有请求。
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?route=$1 [L,QSA]
然后在index.php中你可以做类似的事情(请注意这需要以安全的方式实现,下面是粗略的概述):
<?php
// Copy route into variable.
$route = $_GET['route'];
$slugs = array_filter(explode('/', $route));
// Check there is a slug. e.g. a-great-movie
if(count($slugs) > 0) {
// Perform a SQL/Database query here so see if $slug[0] matches a movie.
// Oviously do this with you database of chose and sanitise input.
// e.g. SELECT id FROM movies WHERE slug = $slug[0]
// Check a match was found if so load your page content.
if($result->rowCount() > 0 ) {
// Show page content.
}
else {
// Show a 404 page?
}
}
else {
// Show homepage.
}
完成上述操作后,您现在可以访问以下网址:
xyz.com/a-great-movie
xyz.com/another-great-movie
当然,您也可以使用您选择的路由库做所有事情。