我试图首先使用.htaccess隐藏我的.php扩展名。在将其包含在文件中之后它确实正常工作
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
还包括我的function.php
//==== Strip .php extension from requested URI
function strip_php_extension()
{
$uri = $_SERVER['REQUEST_URI'];
$ext = substr(strrchr($uri, '.'), 1);
if ($ext == 'php')
{
$url = substr($uri, 0, strrpos($uri, '.'));
redirect($url);
}
}
//==== Redirect. Try PHP header redirect, then Java, then http redirect
function redirect($url)
{
if (!headers_sent())
{
/* If headers not yet sent => do php redirect */
header('Location: '.$url);
exit;
}
else
{
/* If headers already sent => do java redirect */
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
/* If java is disabled => do html redirect */
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0; url='.$url.'" />';
echo '</noscript>';
exit;
}
}
事情是动态页面的网址没有改变..我还有page.php?p = 5 和blog.php?post = 5没有改为页面?p = 5和博客?post = 5 ..
我确实想将上面的动态网页网址改为像www.yourdomian.com/5这样的内容,对于page.php和www.yourdomain.com/blog/5这个博客,但这不是从我的在htacces中重写规则
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?p=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?p=$1
请指出我正在做错的方向。以及如何解决它。
答案 0 :(得分:1)
您可以在/MyApp/.htaccess
中使用这些规则:
Options -MultiViews
RewriteEngine On
RewriteBase /MyApp/
RewriteCond %{THE_REQUEST} /page\.php\?([a-z])=([^&\s]+)
RewriteRule ^ %1/%2? [R=302,NE,L]
RewriteCond %{THE_REQUEST} /blog\.php\?post=([^&\s]+) [NC]
RewriteRule ^ blog/%1? [R=302,NE,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^blog/([^/]+)/?$ blog.php?post=$1 [L,NC,QSA]
RewriteRule ^([a-z])/([^/.]+)/?$ page.php?$1=$2 [L,QSA]