这个问题已经在这里有一个答案:
- 参考:mod_rewrite的,URL重写和“相当链接”解释 4个回答
我试图使用PHP,使搜索引擎友好的网站...
在文件夹J检查我有取一个参数“ID”作为输入的index.php文件。
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
我怎样才能使它发挥作用?
你基本上可以做到这2种方式:
与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,配置和数据库相关网址等零星使用在.htaccess中硬编码的重写规则会做得很好,虽然更大的灵活性。
*****此内容来自复制网址与PHP重写 **
在您的J检查目录中的htaccess文件,请使用以下规则:
RewriteEngine On
RewriteBase /jcheck/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index.php?id=$1 [L,QSA]
试试这个:
RewriteRule ^jcheck/([0-9]+)$ jcheck/index.php?id=$1
RewriteEngine on
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