SEO Friendly URL to Dynamic Arabic Category URL using PHP

谁说胖子不能爱 提交于 2019-12-07 01:16:32

You can use the following rule to map every request that’s URI path does only contain a single path segment onto the index.php while excluding existing files:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^/]+$ index.php?cat=$0 [L]

Note that you actually have to request /مال_وأعمال to have it internally rewritten to /index.php?cat=مال_وأعمال.

First of all you need to create a catch all subdomain which will send all requests to your single VirtualHost:

ServerAlias *.website.com

Then you can either:

  1. Inspect the HTTP host at the application level and do whatever needs to be done (either serve content from the virtual subdomain, or do a 301 redirect to the www.
  2. Use a single mod_rewrite rule to rewrite the URL as you initially suggested.

You can still use the mod_rewrite solution. The trick is the [L] parameter, meaning to stop mod_rewriting after that line. Suppose you have three pages "index.php", "about_us.php", and "contact_us.php", then anything else that they type you want to redirect to a category. You could do something like the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule index\.php index.php [L]
RewriteRule about_us(\.php)? about_us.php [L]
RewriteRule contact_us(\.php)? contact_us.php [L]
RewriteRule (.*) index.php?cat=$1
</IfModule>

This way if they go to index.php (or just index) they get your index.php file. If they go to about_us.php (or just about_us) they get your about_us.php file. But if they go to test (which wasn't specified in the first three lines) they get redirected to index.php?cat=test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!