Basel Ajarmeh
Basel Ajarmeh

Reputation: 35

SEO Friendly URL to Dynamic Arabic Category URL using PHP

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

Upvotes: 1

Views: 2786

Answers (3)

Gumbo
Gumbo

Reputation: 655269

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

Upvotes: 1

stevendesu
stevendesu

Reputation: 16791

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

Upvotes: 0

cherouvim
cherouvim

Reputation: 31903

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.

Upvotes: 0

Related Questions