Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php搜索引擎优化友好的url_Php_Html_.htaccess_Seo - Fatal编程技术网

使用php搜索引擎优化友好的url

使用php搜索引擎优化友好的url,php,html,.htaccess,seo,Php,Html,.htaccess,Seo,我试图使搜索引擎优化友好的网站使用php 在文件夹jcheck中,我有一个index.php文件,它以一个参数“id”作为输入 mydomain.com/jcheck/index.php?id=1 works 我怎样才能做到以下几点 mydomain.com/jcheck/1 我试过制作.htaccess文件并将 RewriteEngine on RewriteCond %{REQUEST_URI} 1/ RewriteRule 1/ http://mydomain.com/jcheck/

我试图使搜索引擎优化友好的网站使用php

在文件夹jcheck中,我有一个index.php文件,它以一个参数“id”作为输入

mydomain.com/jcheck/index.php?id=1 works
我怎样才能做到以下几点

mydomain.com/jcheck/1
我试过制作.htaccess文件并将

RewriteEngine on

RewriteCond %{REQUEST_URI} 1/
RewriteRule 1/ http://mydomain.com/jcheck/index.php?id=1
我怎样才能让它工作

RewriteEngine on
RewriteRule ^/jcheck/([0-9]+)$ /jcheck/index.php?id=1
另请参见,它将对您非常有用

试试这个:

RewriteRule ^jcheck/([0-9]+)$ jcheck/index.php?id=$1

将.htaccess文件放入
jcheck
文件夹并写入:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-D
RewriteRule ^1/?$ index.php?id=1

您基本上可以通过两种方式实现这一点:

FallbackResource index.php
带有mod_rewrite的.htaccess路由

在根文件夹中添加名为.htaccess的文件,并添加如下内容:

RewriteEngine on
RewriteRule ^/Some-text-goes-here/([0-9]+)$ /picture.php?id=$1
这将告诉Apache为此文件夹启用mod_rewrite,如果询问它与正则表达式匹配的URL,它会在内部将其重写为您想要的内容,而最终用户不会看到它。简单,但不灵活,因此,如果您需要更多动力:

PHP路线

将以下内容放在.htaccess中:

FallbackResource index.php
这将告诉它运行index.php来处理所有它在站点中通常找不到的文件。然后,您可以在其中执行以下操作,例如:

$path = ltrim($_SERVER['REQUEST_URI'], '/');    // Trim leading slash(es)
$elements = explode('/', $path);                // Split path on slashes
if(count($elements) == 0)                       // No path elements means home
    ShowHomepage();
else switch(array_shift($elements))             // Pop off first item and switch
{
    case 'Some-text-goes-here':
        ShowPicture($elements); // passes rest of parameters to internal function
        break;
    case 'more':
        ...
    default:
        header('HTTP/1.1 404 Not Found');
        Show404Error();
}
这就是大型网站和CMS系统所做的,因为它在解析URL、配置和数据库相关URL等方面具有更大的灵活性。对于偶尔使用的情况,.htaccess中的硬编码重写规则也可以


*****从jcheck目录中htaccess文件的**

复制此内容,请使用以下规则:

RewriteEngine On
RewriteBase /jcheck/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index.php?id=$1 [L,QSA]

在此服务器上找不到请求的URL/jcheck/1/。它不起作用。请给我找不到404error@user1853803你把.htaccess文件放在jcheck里面了吗?是的,我把.htaccess放在jcheck里面了。你能分享你真正的URL吗?我想现在它的缓存问题是输入url时会出现什么?找不到请求的url/jcheck/3/在此服务器上找不到。请求的url/jcheck/3在此服务器上找不到。@user1853803您确定正在处理htaccess文件吗?在一个空白的htaccess文件中,这些规则对我来说很好。是否需要任何权限或其他东西set@user1853803您需要
AllowOverride FileInfo
allowveride All
在vhost/server配置中如何检查是否处理了.htaccess文件这是一个很酷的解决方案第二个,但是它不是比第一个慢吗?对我来说,
count($elements)
包含根调用的空字符串(home)。它可以用空字符串的大小写捕获(即
大小写“”:
)。另外,
FallbackResource index.php
在根目录上失败。取而代之的是,我用传统的mod_重写了它。我有很多与上面相同的url。因此,使用mod_rewrite在.htaccess路由中逐个创建define。如果你能定义一次。请回答