SEO Friendly URL to Dynamic Arabic Category URL using PHP

空扰寡人 提交于 2020-01-03 03:11:08

问题


Currently I have a url like this

domain/index.php?cat=مال_وأعمال

I want to set things up so that our Marketing people can publish url's like

domain/مال_وأعمال

I've tried several solutions including:

mod_rewrite - the problem with this approach is that it becomes a huge .htaccess file since we need to write a rule for each category.

RewriteMap - this came pretty close since I could query the database to build map file for output. However, I've since learned we don't have access to httpd.conf.

index.php - I've tried running everything through our index.php file which works, but doesn't keep the URL in the browser friendly for SEO purposes.

I'm hoping somebody has another idea which might help, I'd really appreciate it. If you've got a reference to something on the web that would help that'd be great too.

php .htaccess mod-rewrite seo-friendly


回答1:


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=مال_وأعمال.




回答2:


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.



回答3:


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



来源:https://stackoverflow.com/questions/3952200/seo-friendly-url-to-dynamic-arabic-category-url-using-php

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