You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.htaccess阿拉伯语Slug支持问题及全局移除-cat需求

Hey Kareem, let's tackle your two requirements step by step. Here's the modified .htaccess configuration that supports Arabic slugs and removes all -cat references entirely, plus a breakdown of the changes:

Modified .htaccess Code

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /

# Category rules (updated to remove "-cat" and support Arabic)
RewriteRule ^([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)-([0-9_-]+)-([0-9_-]+)-([0-9_-]+)$ cat1.php?id1=$2&id2=$3&id3=$4&id4=$5 [QSA]
RewriteRule ^([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)-([0-9_-]+)-([0-9_-]+)$ cat1.php?id1=$2&id2=$3&id3=$4 [QSA]
RewriteRule ^([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)-([0-9_-]+)$ cat1.php?id1=$2&id2=$3 [QSA]
RewriteRule ^([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)$ cat1.php?id1=$2 [QSA]
RewriteRule ^([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)$ cat1.php?id1=$2
RewriteRule ^([a-zA-Z0-9_\u0600-\u06FF-]+)--([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)-([a-zA-Z0-9_\u0600-\u06FF-]+)$ cat1.php?id1=$3&id2=$4
RewriteRule ^cat([a-zA-Z0-9_\u0600-\u06FF-]+)-([a-zA-Z0-9_\u0600-\u06FF-]+)$ cat1.php?id1=$1&id2=$2
RewriteRule ^cat([a-zA-Z0-9_\u0600-\u06FF-]+)$ cat1.php?id1=$1&v=3

# Item rules (updated to support Arabic)
RewriteRule ^itm([a-zA-Z0-9_\u0600-\u06FF-]+)-edit$ artikel.php?id=$1&create=edit
RewriteRule ^itm([a-zA-Z0-9_\u0600-\u06FF-]+)-create$ artikel.php?id=$1&create=created
RewriteRule ^itm([a-zA-Z0-9_\u0600-\u06FF-]+)$ artikel.php?id=$1 [QSA]

# Other page rules (updated to support Arabic)
RewriteRule ^a/([a-zA-Z0-9_\u0600-\u06FF-]+).html$ index.php?id=$1
RewriteRule ^b/([a-zA-Z0-9_\u0600-\u06FF-]+)/(.*?)$ kate.php?id=null

ErrorDocument 404 /index.php?error=pagenotload

Key Changes Explained

1. Adding Arabic Support to Slugs

  • Every character set regex like [a-zA-Z0-9_-] was updated to [a-zA-Z0-9_\u0600-\u06FF-]. The \u0600-\u06FF range covers all standard Arabic Unicode characters, so your slugs can now include Arabic text without being stripped or replaced.
  • If your server supports PCRE Unicode properties (most modern Apache setups do), you can use the cleaner [a-zA-Z0-9_\p{Arabic}-] instead—it includes all Arabic script characters, including extended variants.

2. Removing All -cat References

  • I went through every rewrite rule and removed the -cat string entirely:
    • For example, the original rule ^([a-zA-Z0-9_-]+)-cat([a-zA-Z0-9_-]+)-... became ^([a-zA-Z0-9_\u0600-\u06FF-]+)([a-zA-Z0-9_\u0600-\u06FF-]+)-...—I adjusted the capture group numbers to ensure the parameters still map correctly to your PHP files (e.g., id1 still pulls from the right segment of the URL).
    • All other instances of -cat in the rules were deleted, ensuring no traces of it remain across the entire .htaccess file.

Quick Note

If you need to redirect old URLs that include -cat to the new clean URLs (to preserve SEO or user links), you can add additional 301 redirect rules at the top of the file, like:

# Redirect old URLs with "-cat" to new ones
RewriteRule ^([a-zA-Z0-9_-]+)-cat([a-zA-Z0-9_-]+)-([0-9_-]+)-([0-9_-]+)-([0-9_-]+)$ $1$2-$3-$4-$5 [R=301,L]
# Repeat similar redirects for other old rule patterns

内容的提问来源于stack exchange,提问作者Kareem Tarek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:36:22