.htaccess rewrite pretty url - .htaccess

I'm new to .htaccess coding and I'm finding it way more confusing than html and css. I want to make my url's more seo friendly and just easier for my users. My current code isn't working. I want to make my urls look like my example below. Let me know if it's possible, I'd prefer not to show my id numbers.
example url
http://mobile.mixtapemonkey.com/artist?a=96/2-chainz
solutions I can live with
.com/2-chainz
.com/a/2-chainz
.com/artist/2-chainz
RewriteCond %{THE_REQUEST} \s/+artist\?a=([^&]+)&t=([^\s&]+) [NC]
RewriteRule ^ a/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+)/([^/]+)/?$ artist.php?a=$1&t=$2 [L,QSA,NC]

If you accept the rewrites with the ID in URL, try the following:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /artist\?a=(\d+)/(\S*) [NC]
RewriteRule ^ a/%1/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^a/(\d+)/(.*)/?$ artist.php?a=$1/$2 [L,QSA,NC]
It'll rewrite the URL: http://mobile.mixtapemonkey.com/artist?a=96/2-chainz to: http://mobile.mixtapemonkey.com/a/96/2-chainz.

Related

Rewrite rule for friendly URLs to yazidetay.php is not working from htaccess

I'm trying to get SEO Friendly URLs to work for my website using the following htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /yazidetay.php\?yazi_sef=([^&]+)&id=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /yazidetay.php?id=$1&yazi_sef=$2 [L]
i want it to change
/yazidetay.php?yazi_sef=deneme-yazisi&id=8
to
/yazidetay.php/deneme-yazisi/8
but it doesn't work.

Redirect to anothe page using .htaccess

I want to redirect the url of http://sitename/modules/fb/fb.php to http://sitename/modules/take_control .How can i do that using htaccess
I tried like
RewriteRule ^/?modules/fb/fb\.php$ take_control , Is that right ?
Your solution is the opposite of what you most likely want if you are trying to rewrite to take_control.
Give this a try. These rules should provide the rewrite with take_control as the URI both ways.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /+modules/fb/fb\.php [NC]
RewriteRule ^ /take_control/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^take_control/?$ /modules/fb/fb.php [L]

Removing part of URL but don't redirect with htaccess

So the problem I'm looking at and haven't managed to solve!
For example the url is http://someurl.com/brands/brand
What I want to accomplish is that htaccess lets te request go to url: http://someurl.com/brands/brand but removes the "brands" part from the url.
Also if the url: http://someurl.com/brands is called the page "brands" needs to be displayed. So only when there is a brand after /brands/ it needs to do a URL rewrite to http://someurl.com/brand
I have tried this but this piece does a redirect to the new location witch doesn't exist.
RewriteRule ^onze-merken/(.*)$ /$1 [L,R=301]
So I need the above with out the redirect, it only needs to rewrite the URL.
Any help would be greatly appreciated, Thanks!
This is now my htaccess part where the rewriting is done!
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /onze-merken/(\S+)\s [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# Only rewrite if the directory doesn't exist.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# internal forward from pretty URL to actual one
RewriteRule ^((?!onze-merken/).+)$ /onze-merken/$1 [L,NC]
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
RewriteRule ^(uploads/([a-z0-9_\-\.]+)/__images/custom/(.*)/)(.*)$ http://someurl.com/uploads/$2/__images/custom/$3/$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /brands/(\S+)\s [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!brands/).+)$ brands/$1 [L,NC]

Redirect url get variables after rewriting htaccess

My original url was this:
wwww.domain.com/car-details.php?merk=BMW&model=X5&titel=sale&car_id=3
I have Rewrite it into this:
wwww.domain.com/BMW/X5/sale/3
By putting this in my .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/([0-9]+)?$ /car-details.php?merk=$1&model=$2&titel=$3&car_id=$4 [L,QSA]
When i put in Url wwww.domain.com/car-details.php?merk=BMW&model=X5&titel=sale&car_id=3 it still works. I want that url to be redirected to wwww.domain.com/BMW/X5/sale/3
I have tried to put the [R] flag in my htaccess RewriteRule but then I'm getting the opposite results.
How can I fix this?
This is a good decision to do what you want.
But you will face a loop problem.
You can avoid it by using this code
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/car-details\.php\?merk=([^&]+)&model=([^&]+)&titel=([^&]+)&car_id=([0-9]+) [NC]
RewriteRule . /%1/%2/%3/%4? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([0-9]+)?$ /car-details.php?merk=$1&model=$2&titel=$3&car_id=$4 [L]

htaccess rewriting if statements

I am working on a twitter/facebook type site for a college class. Somehow they let a professor teach this class with no PHP, CSS, HTML, JavaScript,jQuery, or Ajax knowledge. I have been trying to rewrite my URLs to make them look like twitter. I have gotten all of my user profile pages to rewrite to: www.site.com/username from: www.site.com/profile.php?name=username. However, I also want to rewrite my login page, create account page, etc. Currently they are: www.site.com/login.html , www.site.com/createAccount.html. I want the to rewrite without the html. Here is my .htaccess file currently.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?name=$1 [L]
**Update
I apologize I ended up switching all of my files over to .php. But I am still having some issues. Now, I only want to redirect specific URLs. For example: www.361orc.info/login should internally redirect to www.361.orc.info/login.php . I cannot seem to figure out what is wrong with the following code. It redirects but it does it changes the client URL. I want it to just redirect internally. Here is my .htaccess file:
RewriteEngine On
#I want this code to change .com/login.php to .com/login but only internally
#the URL in the client's browser shouldn't change
RewriteCond %{REQUEST_FILENAME} !-
RewriteRule ^login?$ login.php [L]
#Change the profile pages of users from .com/profile.php?name=user to .com/user
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ /profile.php?name=$1 [L,QSA]
you could do something like this
# Rewrite User Profiles
RewriteCond %{QUERY_STRING} ^name=([^&]+) [NC]
RewriteRule ^profile.php$ /%1 [R=301,L]
# Rewrite Login
RewriteRule ^login.html$ /login [R=301,L]
# Rewrite Create Account
RewriteRule ^createAccount.html$ /createAccount [R=301,L]
You are pretty close, just an external redirection rule that will redirect .html files to ones without .html extension:
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+?)/?$ $1.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ profile.php?name=$1 [L,QSA]

Resources