Mod rewrite doesn't work with some persian words - .htaccess

I'm working on a website in which I need to use mod_rewrite to pass some Persian words to my php file and then catch them in php and do the rest of the processes.
I've done the .htaccess file configurations like those on the web, but the problem is that it works on some words and doesn't work on some others.
Here is my .htaccess file:
RewriteEngine On
RewriteRule ^cat/thumb/([^.]+\.jpg)$ getpic.php?name=$1&thumb=true [L,QSA,NC,NE]
RewriteRule ^cat/([^.]+\.jpg)$ getpic.php?name=$1&thumb=false [L,QSA,NC,NE]
RewriteRule ^cat(.*)$ cats.php?fn=$1 [NC,L,NE]
RewriteRule ^([0-9]+)$ job.php?j_id=$1 [NC,L,NE]
The one that's problematic is the third rule.
For example it works on these URLs:
http://kodaa.com:81/jobs/cat/-%DA%AF%D8%B1%D8%A7%D9%81%DB%8C%DA%A9-%D8%B9%DA%A9%D8%B3
http://kodaa.com:81/jobs/cat/-%DA%AF%D8%B1%D8%A7%D9%81%DB%8C%DA%A9-%D8%B9%DA%A9%D8%B3-%D8%B7%D8%B1%D8%A7%D8%AD%DB%8C%20%D8%A2%DB%8C%DA%A9%D8%A7%D9%86
but doesn't work on these ones:
http://kodaa.com:81/jobs/cat/-%D8%B1%D8%A7%DB%8C%D8%A7%D9%86%D9%87-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87%20%D9%86%D9%88%DB%8C%D8%B3%DB%8C
http://kodaa.com:81/jobs/cat/-%D8%AA%D8%B1%D8%AC%D9%85%D9%87
What am I doing wrong?

Related

Rewrite multiple sub-directories to the same path htaccess

I want to rewrite multiple sub-directories to the same path. while I can remove a part from URL Apache htaccess
for example, I want
domain.com/category/computer/internet-topics
domain.com/category/computer/windows-topics
domain.com/category/science/physics-topics
domain.com/category/science/biology-topics
to be
domain.com/category/internet-topics
domain.com/category/windows-topics
domain.com/category/physics-topics
domain.com/category/biology-topics
When I use this, it works fine for the first line only (computer)
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9_-]+)$ category/computer/$1
RewriteRule ^category/([a-zA-Z0-9_-]+)$ category/science/$1
I think you need to be specific else only first rule will be used
RewriteEngine On
RewriteRule ^category/((internet)|(windows)-topics)$ category/computer/$1
RewriteRule ^category/((physics)|(biology)-topics)$ category/science/$1

htacces rewrite single file

I want to rewrite a specific file on my website to another one by using htaccess:
# General
RewriteEngine On
RewriteBase /
Options All -Indexes
Options +FollowSymLinks
# Rewrite file
RewriteRule ^/file.html$ /dir/file.html [L]
This is the .htaccess code i'm using based on snippets i found on the internet.
Somehow this is not working, the server is returning a 404-Not-found error.
I can't see any difference with example's that are said to work, like in
Rewriting path for a specific file using htaccess
Edit:
If I place file.html in the root-folder, I can view it. So the rewrite definitely is not happening.
RewriteRule does not receive leading slash. Write so:
RewriteRule ^file.html$ /dir/file.html [L]

Rewrite basic $_GET variable to friendly URL using mod_rewrite

I know questions similar to this are common. I just don't even know where to begin with rewrite rules with the /'s and .'s I don't know how to retrofit other peoples solutions to mine. Onto my situation:
I am using a basic get on the index.php file that looks like
http://www.example.com/index.php?page=about
I want to rewrite that to
http://www.example.com/about
I know this is fairly simple rewrite wise, but its just a totally different language which I have tried and failed to comprehend. Thanks
Try this:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
Or even:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(?!index.php\b).* index.php?page=$0 [L,QSA]
Note:
You should always set the RewriteBase in an .htaccess file.
I've generalised this so that index.php picks up any string which isn't mapping to a real file
The (?!index.php\b) is a regexp which says "but don't match to index.php"
You will need the [QSA] flag if your requests can contain request parameters. This merges them.

rewrite php file in htaccess with our without query string

So I have photographs.php, and there are also sections where it will be rewritten as photographs.php?cat=somecategory
Question is, in .htaccess how do I get these both to work as such
/photographs
and
/photographs/somecategory
so that the $_GET['cat'] variable will be = somecategory
/photographs/(.+) will need to redirect to photographs.php?cat=$1, while /photographs/? will just redirect to photographs.php. if you want to be clever, you can combine it and do it in one line and /photograph will just go to photographs.php?cat=[blank].
First of all you must have the mod_rewrite module activated.
Here's what you need to add to your .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^photographs$ photographs.php [NC]
RewriteRule ^photographs/(.*)$ photographs.php?cat=$1 [NC]
Just some simple replace rules. You can find lots of info on the web about them.

Make Folders in Apache Case Insensitive using .htaccess

I need to make accessing directories on my server case insensitive.
How do I do that using htaccess?
You have to install and enable the mod_speling module in apache and set the CheckCaseOnly Directive to On in your .htaccess
CheckCaseOnly On
If you want requested URLs to be valid whether uppercase or lowercase letters are used, use mod_speling to make URLs case-insensitive. Write the following code in .htaccess file:
CheckSpelling On
This is what I used because my hosting is shared and does not include the mod_spelling module but does support .htaccess, but this only works for one folder:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^student-government/$ http://www.tombarrasso.com/Student-Government/ [R=302,NC,L]
The folder to redirect to can be any case, so you could use lower-case folders and redirect all variations of spelling there.
I suppose it could be adapted with a little bit of REGEX to work for all folders rather than just one. This worked for me on Apache 2.2.14 (Unix).
Solution-1: To make case-insensitive directory and files names with respect to the requested URL we can add the following two lines to the app's .htaccess file:
<IfModule mod_speling.c>
#Once enabled, mod_speling redirects misspelled requests to any nearest matching resources. Uses a bit of memory, but can be useful if you've been changing URIs or have lots of similarly named URIs:
CheckSpelling On
CheckCaseOnly on
</IfModule>
Solution-2:
Again if we want just a few predefined directories to go to specific directories, then apply the below lines instead:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^my-dir/old-dir-1/$ /my-dir/new-dir-1/ [R=301,L,NE]
RewriteRule ^my-dir/old-dir-2/$ /my-dir/new-dir-2/ [R=301,L,NE]
RewriteRule ^my-dir/old-dir-3/$ /my-dir/new-dir-3/ [R=301,L,NE]
# For any case insensitive directories we can try adding NO-CASE (NC)
RewriteRule ^My-Old-Dir/$ /my-new-dir/ [R=301,L,NC]
</IfModule>

Resources