[英]Changing Page URL To PHP
Hi I want to convert pages URL like www.example.com/pictures.php?title=yyoy
to something like www.example.com/page/yoyo.php
嗨,我想将网页网址(例如www.example.com/pictures.php?title=yyoy
转换为类似www.example.com/page/yoyo.php
How can I do this? 我怎样才能做到这一点?
www.example.com/pictures.php?title=yyoy
these pages are generated when someone upload image to my website so I want to turn these types of URL to like above shown example. www.example.com/pictures.php?title=yyoy
这些页面是在有人将图像上传到我的网站时生成的,因此我想将这些类型的URL转换为上面显示的示例。
Because these pages can't be index in search engines. 因为这些页面无法在搜索引擎中建立索引。 Thanks 谢谢
Picture.php Picture.php
<?php
include("connection.php");
if(isset($_GET['title'])){
$page_id = $_GET['title'];
$select_query = "select * from save_data where Title='$page_id'";
$run_query = mysql_query($select_query);
while($row=mysql_fetch_array($run_query)){
$post_id = $row['ID'];
$post_title = $row['Title'];
$post_image = $row['Name'];
$page_title = $_GET['title'];
header('uploads/ ' . $page_title . '.php')
?>
<center>
<h2>
<a href="pictures.php?title=<?php echo $post_title; ?>">
<?php echo $post_title; ?>
</a></center>
</h2>
<center><img src="uploads/<?php echo $post_image; ?>" /></center>
<?php } }?>
I have not tested this, but you should use rules similar to the following in your .htaccess
file: 我尚未对此进行测试,但是您应该在.htaccess
文件中使用类似于以下规则:
RewriteEngine on
RewriteRule ^pictures.php?title=(.+)$ page/$1.php [R]
Note that, you will need mod_rewrite
enabled for this to work in apache2
请注意,您需要启用mod_rewrite
才能在apache2
工作
Usually I would create an in-between page when posting from a form, but in your case your link looks like this: 通常,从表单发布时,我会在中间创建一个页面,但是在您的情况下,您的链接如下所示:
www.example.com/pictures.php?title=yoyo
So it directs you to pictures.php with a variable 'title' in the URL. 因此,它会将您定向到在URL中带有变量“ title”的pictures.php。
So on your pictures.php page use: 因此,在您的pictures.php页面上使用:
$page_title = $_GET['title'];
And when you want to go to yoyo.php: 而当您想转到yoyo.php时:
header('Location: $page_title.php')
From your edit this code will redirect the page but it will not display the last HTML: 通过您的编辑,此代码将重定向页面,但不会显示最后的HTML:
<?php
include("connection.php");
if(isset($_GET['title'])){
$page_id = $_GET['title'];
$select_query = "select * from save_data where Title='$page_id'";
$run_query = mysqli_query($select_query);
while($row=mysqli_fetch_assoc($run_query)){
$post_id = $row['ID']; //Just make sure the values between [''] match -
$post_title = $row['Title']; //your columns in database.
$post_image = $row['Name'];
}
header('Location:uploads/$post_title.php');
?>
This will be left out: 这将被忽略:
<center>
<h2>
<a href="pictures.php?title=<?php echo $post_title; ?>">
<?php echo $post_title; ?>
</a></center>
</h2>
<center><img src="uploads/<?php echo $post_image; ?>" /></center>
<?php } }?>
There's a good answer here: Masking $_GET variables of the URL when passing pages in PHP That will tell you how to mask your URLs. 这里有一个很好的答案: 在PHP中传递页面时,请屏蔽URL的$ _GET变量,这将告诉您如何屏蔽URL。
Alternatively, you could have these files uploaded to a directory in your file structure called "page/" Then you can access the files (as a download) inside the page directory with www.example.com/page/filename.php 或者,您可以将这些文件上载到文件结构中的名为“ page /”的目录中,然后可以使用www.example.com/page/filename.php访问页面目录中的文件(作为下载)。
URE This one URE这个
RewriteEngine on
RewriteRule ^pictures.php?title=(.+)$ page/$1.php [R, L]
You should use the .htaccess file. 您应该使用.htaccess文件。 Add this: 添加:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^picture/([a-zA-Z0-9]+).php$ pictures.php?title=$1
</IfModule>
If you're using a local server like WAMP, be sure to turn on de mod_rewrite
or rewrite_module
of apache and reboot the server. 如果您使用的是WAMP之类的本地服务器,请确保打开apache的de mod_rewrite
或rewrite_module
并重新启动服务器。
You should also Google for Regular Expressions. 您还应该使用Google for Regular Expressions。 Let me know if it was useful. 让我知道它是否有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.