drpqxogph15436713 2016-09-11 01:20
浏览 16
已采纳

对于动态加载的页面,我可以使用htaccess在URL中使用连字符吗?

I'm creating a forum, and after sanitizing the slugs I want them to look like so for the url slug this-is-my-thread-09-10-16-6-18pm, I have everything called from the index.php file and it simply rewrites the urls. Is there anyway to allow the - to be used in the dynamic call? Right now they simply return a 404 error. My current .htaccess file

RewriteEngine On

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(\w+)/?$ index.php?ident=$1 [L,QSA]
RewriteRule ^(\w+)/(\w+)/?$ index.php?ident=$1&ident2=$2
RewriteRule ^(\w+)/(\w+)/(\w+)/?$ index.php?ident=$1&ident2=$2&ident3=$3 [L,QSA]
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)/?$ index.php?ident=$1&ident2=$2&ident3=$3&ident4=$4 [L,QSA]
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)/(\w+)/?$ index.php?ident=$1&ident2=$2&ident3=$3&ident4=$4&ident5=$5 [L,QSA]
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)/(\w+)/(\w+)/?$ index.php?ident=$1&ident2=$2&ident3=$3&ident4=$4&ident5=$5&ident6=$6 [L,QSA]
RewriteRule ^(\w+)/(\w+)/(\w+)/(\w+)/(\w+)/(\w+)/(\w+)/?$ index.php?ident=$1&ident2=$2&ident3=$3&ident4=$4&ident5=$5&ident6=$6&ident7=$7 [L,QSA]


php_value max_execution_time 300
  • 写回答

1条回答 默认 最新

  • doudu3961 2016-09-11 01:28
    关注

    \w is a PCRE regex base class for (a-z 0-9 _). It doesn't match hyphen - characters. Only letters from a to z, number characters from 0 through 9 and underscore characters _. You will need to specify the hyphen yourself using [a-z0-9-]+. Unless you also want the underscore in there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏