.htaccess 使用url剪切将url重写到根目录
我有这样的网址:.htaccess 使用url剪切将url重写到根目录,.htaccess,.htaccess,我有这样的网址: http://site.ru/ontent/wefwefw/article.php?article=369-tayskaya-kuhnya-recept-s-foto http://site.ru/ontent/wefwefw/article.php?article=32237-ogurci-recepti-na-zimu http://site.ru/ontent/wefwefw/article.php?article=90-ogurci-na-zimu-recepti-po
http://site.ru/ontent/wefwefw/article.php?article=369-tayskaya-kuhnya-recept-s-foto
http://site.ru/ontent/wefwefw/article.php?article=32237-ogurci-recepti-na-zimu
http://site.ru/ontent/wefwefw/article.php?article=90-ogurci-na-zimu-recepti-po-koreyski
我想重写tham,比如:
http://site.ru/tayskaya-kuhnya-recept-s-foto.html
http://site.ru/ogurci-recepti-na-zimu.html
我试过smth,比如:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ontent/wefwefw/$1 [L]
但是,如何减少字符串中不必要的部分呢?除非article.php能够单独从标题中派生出正确的文章,否则您不可能做到这一点。mod_rewrite擅长重写内容,但如果它不在原始请求中,它就不能凭空调用文章id。你会有这样的想法:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)\.html$ ontent/wefwefw/article.php?article=$1 [L]
您何时请求
http://site.ru/tayskaya-kuhnya-recept-s-foto.html
,它将加载http://site.ru/ontent/wefwefw/article.php?article=tayskaya-kuhnya-recept-s-foto
。如果需要,您必须根据标题以其他方式获取id 369。在这种情况下,最好的方法是:
http://site.ru/369-tayskaya-kuhnya-recept-s-foto.html
重定向到
http://site.ru/ontent/wefwefw/article.php?article=369
与:
你不能直接用mod_rewrite来做,因为你有一些
ID
变量参数链接到你的URL中的每篇文章
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+)-[^/]*\.html$ ontent/wefwefw/article.php?article=$1 [L]