Question

Here's my code that allows me to change

mydomain.com/?name=something&action=something&other=something

to

mydomain.com/something/something/something

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} -d [OR] 
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteRule .* - [L]

RewriteRule ^(\w+)/(\w+)/(\w+)/?$ /index?name=$1&action=$2&other=$3
RewriteRule ^(\w+)/(\w+)/?$ /index.php?name=$1&action=$2
RewriteRule ^(\w+)/?$ /index.php?name=$1

But sometimes the first "something" could be something with a space in it and I'm not quite sure how to format it. e.g. "something very random". I know the url formats it with a %20 but how could I do this with .htaccess so the url could be

mydomain.com/something very random/somethng/something

also the first word will trail with a - and a random number e.g. -4738

e.g. mydomain.com/something very random-4738/something/something

how would I pick this up with the .htaccess code I am using?

Was it helpful?

Solution

Replace your code with this one

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} -d [OR] 
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -l
RewriteRule .* - [L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?name=$1&action=$2&other=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?name=$1&action=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ /index.php?name=$1 [L,QSA]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top