Regex .htaccess如果URL不正确,请执行某些操作

Regex .htaccess如果URL不正确,请执行某些操作,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,我在做我个人的事情。我想在it中使用酷(友好)的URL。这是我的.htaccess文件代码: RewriteEngine on RewriteBase / DirectoryIndex index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z-_0-9_/]+)/?$ index.php?args=$1 [L] 我看到在堆栈溢出友好的URL也

我在做我个人的事情。我想在it中使用酷(友好)的URL。这是我的.htaccess文件代码:

RewriteEngine on
RewriteBase /
DirectoryIndex index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z-_0-9_/]+)/?$ index.php?args=$1 [L]
我看到在堆栈溢出友好的URL也被使用。今天我试图在堆栈溢出上出错。到(例如)此URL
http://stackoverflow.com/questions/5469955/htaccess-url-rewrite-if-file-not-exists
。我添加了
.php
。但我没有看到404错误。我们的论坛以一种神奇的方式删除了我的postscript,并将我重定向回正确的网站URL如何在我的CMS中实现同样的功能


我试图将此(
RewriteRule^([a-zA-Z-\u 0-9./])/?$index.php?args=$1[L]
)行更改为(
RewriteRule^([a-zA-Z-\u 0-9./])/([a-zA-Z-\u 0-9)$index.php?args=$1[L]
)但是,这是没有帮助的,然后我看到代码> 500内部服务器错误 .< /P> < P>如果你需要和StActFube有相同的行为,那么你必须有一些服务器端支持(例如PHP、ASP等)。 .htaccess: index.php:


什么是NC和QSA标志?NC-无案例比较和QSA-查询字符串附加。请检查此正式文件:
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?id=$1&title=$2 [L,NC,QSA]
<?php
   $id    = $_GET['id'];
   $title = $_GET['title'];

   $dbTitle = // Get title from Database query using $id
   ...
   if ($title != $dbTitle) {
      // Redirect with 301 to correct /<id>/<title> page
      header ('HTTP/1.1 301 Moved Permanently');
      header('Location: /' . $id . '/' . $dbTitle);
      exit;
   }
   // The rest of your script
?>