How to make clean urls with .htaccess - .htaccess

I have this profile page which will show your profile with the url
localhost:8080/profile?username=ImSchnebz
But the thing is I want it to look like this:
localhost:8080/profile/ImSchnebz
I have tried a lot of different answers, but most of them give me 404 not found or 500 internal server error, I know this isn't anything you guys could help me with, but I've asked this question before, and gotten no response, so please, if there is anyone out there, please help me! :)
Thanks
EDIT:
I have this code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /profile.php?username=$1 [L,QSA]
And it works perfectly with localhost:8080/ImSchnebz but I want it to be localhost:8080/profile/ImSchnebz

Try
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/profile/(.*)$ /profile?username=$1 [NC]
Based on the link #Lawrence gave.

Try this:
RewriteEngine on
RewriteBase /
RewriteRule ^profile/(.*)$ profile.php?username=$1 [L,QSA]

Related

mod_rewrite get variable returns Server errors 500

What i'm trying to do is make the link show like this
http://api.example.com/users/useridhere/
Whenever I try to put in the rewrite it gives me a Server Error.
Here is my current code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php?id=$1 [NC,L]
DirectoryIndex index.php?id=Nobody
If anybody could point out what I did wrong or post a fix I will appreciate that.
If I'm understanding correctly, you're wanting to request and see this in the browser:
http://api.example.com/users/useridhere/
But display the contents of:
http://api.example.com/index.php?id=useridhere
If this is accurate, then maybe something like this in your [docroot]/.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^users/([\w-]+)$ index.php?id=$1 [NC,L]

How to use RewriteCond to get rid of duplicate page

Hello guys! I need some help with htaccess, because I'm really stuck with it. I have some pages, like:
site.ru/books
site.ru/pens
And those links can be called by other urls:
site.ru/index.php?show=books
site.ru/index.php?show=pens
I hope you understand those links above are equal. Just, urls are user friendly.
I want to use RewriteCond to make a redirect from "site.ru/index.php?show=books" to "site.ru/books", because Google or other Search Engines don't like duplicate pages.
But the problem is I don't know how to write this… Help me please, and sorry for my bad English ;-)
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index\.php\?show=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?show=$1 [L,QSA]

How to get parameters through mod_rewrite

I have been searching for a long time now with no success, and I am almost there. However, I need to create this rule:
www.webpage.com/index.php?variable=x
to
www.webpage.com/x and www.webpage.com/x/
So far I have this code in .htaccess:
^([^/]*)\.html$ /index.php?nombre=$1 [L]
and what it helps me is in putting getting what I need but with .html
www.webpage.com/x.html
and I need
www.webpage.com/x
Thanks in advance! :D
Assuming you're using mod_rewrite, try:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /index.php?nombre=$1 [L]

mod-rewrite forwarding without changing URL

I have a small problem with my Apache configuration when creating "pretty" URLs. I've got it to the stage where typing (or linkig for that matter) to
index.html
forwards you to
index.php?pageID=Forside
that is exactly what I want.
But how can I get index.html to stay in the address bar of the browser?
Right now it forwards and changes the URL to the original one.
Here my .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} index\.html
RewriteRule .* http://www.radoor-designs.dk/index.php?pageID=Forside [L]
And before someone comments on it: Options +FollowSymLinks is missing since it triggers an error 500 on a one.com webhotel.
Thanks in advance!
Try the following:
RewriteEngine On
RewriteRule ^index\.html$ /index.php?pageID=Forside [L]
I think this may help you to resolve your problem.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.html$ /index.php?pageID=Forside [L]
This will do the redirect for you whilst showing index.html in the browser window.
Strange that symbolic links creates an error 500,
if you want it to redirect to index.html?pageID=Forside then do
RewriteRule .* /index.html?pageID=Forside [QSA,L,R=301]
I'm not 100% certain what you are trying to achieve with this could you explain a little more?

conditional rules htaccess

Currently, my .htaccess file looks like htis:
IndexIgnore */*
RewriteEngine on
RewriteRule ^add /add.php
RewriteRule ^add/$ add.php
RewriteRule ^sitemap.xml /xmlsitemap.php
RewriteRule ^([^/\.]+)$ /index.php?slug=$1
RewriteRule ^([^/\.]+)/$ /index.php?slug=$1
It works fine for links as: site.com/category/
However, i would like the complete slug after site.com/. So that i can redirect site.com/category1/subcategory2/subsubcategory3 etc. There can be an unknown amount of subcategories inside a category.
I tried with request_uri but that didn't really work out.
How to do this? Thanks a bunch!
EDIT:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* slug.php?%{QUERY_STRING} [L]
this will pass URL to slug.php
ok, got it. it's simply: deleting the ^/. from the regex. i just figured that means that it has to stop at any / :) but... thx! it works now! :)

Resources