I have a domain that looks like this when i visit certain link https://domain.com/model-profile/index.php?name=abbychampion
the site is written in php but i dont want to show this part index.php?name= because for SEO purposes and better human reading.
Is this possible to hide ? so the link looks like this https://domain.com/model-profile/abbychampion

Recommended Answers

All 27 Replies

Yes, it's possible, but how to do it depends on if you are using Nginx or Apache.

If it's Apache, you will need to add a mod_rewrite rule to an .htaccess file and upload it to the domain root. The contents of the .htaccess file would look something like this:

RewriteEngine On
RewriteRule ^model-profile/(.*)$ https://domain.com/model-profile/index.php?name=$1 [L]

As for how to do it in nginx, you would need to modify your nginx config file with either the rewrite directive or try_files directive. (You can use try_files to redirect everything to index.php and then have code in index.php figure out what to do based on the format of the URL).

Thank you for your reply but this is redirecting me to a link like this
https://leakedof.us/model-profile/index.php?name=index.php

Which than gives me error "Model profile not found!"

Are you using Apache with the above htaccess file or are you using Nginx? Is there anything else in your htaccess? What is the specific URL you are typing into your web browser?

I am using cPanel and FileManager. I have these lines of code in my htaccess file
RewriteEngine on RewriteRule ^model-profile/(.*)$ https://leakedof.us/model-profile/index.php?name=$1 [L]

the exact url for the model profile is this
https://leakedof.us/model-profile/index.php?name=fitbryceadams

Feel free to visit the website there is 0 nudity. Its a fake website for "leaks"

BTW the website is hosted on KnownSRV.com

I am not sure how do i answer that question between Apache and Nginx :S

I just found out that i am using Apache

I am sorry i cannot edit the answer above.
I just got reply from the admins of the hosting provider that is actually litespeed
I don't really understand whats the difference. But i need this URL shortened for SEO purposes.
Thank you all DANIWEB community

Anyone can help me ?

I'm really sorry. I didn't get much sleep and admit I'm a little loopy, but i really don't see what is wrong with:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$     $1/index.php?name=$2 [L]

That should work, as should the rule I provided before. (This one is a little more flexible)

Update: I just noticed you mentioned you're using Litespeed, not Apache. I have no experience at all with Litespeed, but a little Google research shows that Litespeed does support .htaccess, but you need to enable it by specifying the location of the .hataccess file in your litespeed config. I wish I could help more but I have literally no experience with litespeed. It apparently also works differently depending on if you are using openlitespeed or litespeed enterprise.

Its weird because this code again doesn't work. I copied and pasted exactly as you wrote it.
The path is automatically specified i contacted the support

I got reply from customer support saying that i need to:

"As this is a code-related issue, we have limitations to help you with. Please setup the code htaccess rule for it."

Oh goodness, I see the problem with my recent code. The line:

RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$     $1/index.php?name=$2 [L]

says that the URL should be in the form [alphanumeric word]/[alphanumeric word]. But the folder name has a dash in it (model-profile). So it should really be:

RewriteRule ^([a-z0-9-]+)/([a-z0-9]+)$     $1/index.php?name=$2 [L]

Try that.

Does that work?

This actually works but it has a problem, when i open some of the links error page 404, usually the usernames that have ('.', '_', '-')

https://example.com/model-profile/blondie.sabrina
https://example.com/model-profile/sugar_daddy53
https://example.com/model-profile/woof-n-oink
These usernames have that problem. But when you visit them with the old way they work
https://example.com/model-profile/index.php?name=blondie.sabrina
https://example.com/model-profile/index.php?name=sugar_daddy53
https://example.com/model-profile/index.php?name=woof-n-oink

Please take a look at the website and try to open some of the profiles and you will see that some url's work and some dont. I have removed all the images i have placed this as a example image https://via.placeholder.com/350

Thank you very much for the help

If you look at the rewrite rule I created, it follows the format of A/B where A is a word consisting of lowercase letters, numbers, or a dash, and B is a word consisting just of lowercase letters or numbers.

If you want model-profile/<anything goes> to work, you can do something like this:

RewriteRule ^model-profile/(.+)$     model-profile/index.php?name=$1 [L]

Now i have different problem... when i click some model url.. it redirects me to next page with the correct url format but somehow the sql query cannot find the model
It gives me this error

Fatal error: Wrong SQL: SELECT ID, name, url, profilepic, tags FROM modelprofile WHERE url = 'index.php' Error: in /home/appunloc/leakedof.us/model-profile/index.php on line 34
No profile found in this URL, please make sure it is the correct URL in the address bar!

Here is how i am getting the name parameter in the url at the beggining of the page

<?php
    $profile = $_GET['name'];

    if ($profile == null) {
      header("Location: ../index.php");
    }

$sql = "SELECT ID, name, url, profilepic, tags FROM modelprofile WHERE url = '$profile'"; 
$result = $conn->query($sql);
if(!$result){
  trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
  echo "Something went wrong, please try again.";
} else {
  if($result->num_rows == 0){
      trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
      echo "No profile found in this URL, please make sure it is the correct URL in the address bar!";
  }
?>

And you used the exact code I have above? You don't accidentally have ?name=$2 instead of ?name=$1, right?

Yes here is my exact code in the .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^model-profile/(.+)$     model-profile/index.php?name=$1 [L]

maybe somebody else have some solution about this problem?

I changed the folder model-profile into leaks
Anybody who want post a reply the link should look like this
https://domain.com/leaks/modelName

Since changing the folder name, what does your .htaccess look like?

What did the .htaccess look like when it semi-worked? (e.g. it worked as long as there was no hyphen in the name?)

commented: Yes that is correct it worked without symbols +6

Now the .htaccess file is empty because i was not able to find the correct answer. And i have changed the folder name from model-profile to onewordname. I find it better for SEO purpose

And this doesn't work? ...

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)/(.+)$     $1/index.php?name=$2 [L]

Nope it doesn't work. It displays error "No profile found in this URL"
Wrong SQL: SELECT ID, name, url, profilepic, tags FROM modelprofile WHERE url = 'index.php'

this code works but only with alphanumeric words and not with symbols in the word

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$     $1/index.php?name=$2 [L]

I'm really sorry, I cannot for the life of me figure out why that's happening. I must not be noticing something obvious.

I was just thinking … can you show me the PHP code you’re using to generate the MySQL query?

Question is solved.
The solution is:

RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/(folder)/index\.php\?name=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

##Internal rewrite rules from here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ $1/index.php?name=$2 [QSA,L]

That looks awfully convoluted and confusing. I'm glad you got it working, though!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.