How to remove all /page.html from your URL - .htaccess

So I asked this question before but got none working answer, maybe I defined it in a wrong way.
My question is: How can I remove all / urls from my link.
So for example: the URL right now is: exampledomain.com/a/dashboard.html
But I want it to be: exampledomain.com/ and nothing after it.
So basicly nothing after the example.com/.
Is that possible? I guess it has to be done in the .htaccess file but couldnt find a working rule.
So now it is: exampledomain.com/a/dashboard.html
But I want it to be: exampledomain.com & nothing behind that / when u go to the dashboard.
Thanks for your help

You can try the below rule in .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule .* / [L,R=302]

Related

.htacess url rewrite rule to shortern the url and remove "?st_id=" from it

I currently goto:
support-requests/?st_id=7
Ideally i would like to just go straight here using .htaccess url-rewriting to make the page neater to look at and navigate to without the "?st_id=" being displayed in the url.
support-requests/7
This is what i currently have but i know its wrong and it does not work:
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule support-requests/ support-requests/%1/%2/?
Could i have some assistance in getting this correct please?
Thanks
Use this:
RewriteEngine On
RewriteRule ^support-requests/([^/]*)$ /support-requests/?st_id=$1 [L]
Should leave you with:
www.example.com/support-requests/7

Remove string in .htaccess

I have the following entry in my .htaccess file:
RewriteRule ^blogs$ ?name=data&case=gview&group_id=31%1 [L]
What I do is, I redirect blogs to ?name=data&case=gview&group_id=31
Now what happens is, all my urls are now blogs?id=1 etc, but I need them to stay just ?id=1
How can I remove the blogs from rest of the urls?
This what I came up with, but it doesn't work:
RewriteRule ^blogs?(.*)$ /$1 [L]
EDIT I might be explaining it wrong. I need to change the actual url display of the links. Is that actually possible?
Not sure... but is that what you're looking for ?
RewriteRule ^/?$ /blogs [L,QSA]
What's wrong with just adding a R to your original rule?
RewriteRule ^blogs$ ?name=data&case=gview&group_id=31%1 [L,R=301]
Ok, the answer is pretty much: It can't be done. I just went over my code, added / before main urls and all is working as intended.
Thank you both for suggestions.

.htaccess : Rewriting initial output back into subdomain

I have the following htaccess.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www|m)\.DOMAIN\.com$
RewriteCond %{HTTP_HOST} ^([^\.]+).DOMAIN.com$
RewriteRule ^(.*)$ http://DOMAIN.com/index.php?id=%1 [NC,QSA,L,R=301]
The problem is that although it works I need it to still use the subdomain as the URL. So basically now I'm trying to rewrite DOMAIN.com/index.php?id=%1 back into SUDOMAIN.DOMAIN.com so the user sees the subdomain they requested on the address bar and not the http://domain.com/index.php?id=user
I'ver tried all sorts of things but always end up with some sort of infinite loop. Please help!
I already have a wildcard subdomain set up. In conjunction with the htaccess shown above.
The submain doesn't stick, it rewrites itself into the long string shown above. But what im trying to do is get the url ro remain subdomain.domain.com unfortunately the link you posted does peretty much the same as what I have posted above, doesn't really seem to be able to get the sub-domain to stick.
Any ideas?
Not sure if you figured it out yet, but your last line (I believe) should be this:
RewriteRule ^(.*)$ index.php?id=%1 [NC,QSA,L,R=301]
If that does not work try this:
RewriteRule (.*) index.php?id=%1 [NC,QSA,L,R=301]
No expert but I have subdomains working from some other code I found. Hope it helps.
You need to change your DNS settings before. (A record)
There is already an answer for that question.

Problem with rewrite rule

Can anyone explain to me why this rewrite rule doens't work:
RewriteRule ^architecture/([a-zA-Z_]+)/(.*).html$ web/index.php?field=1&sub=$1&name=$2
on this url: http://localhost/greenlinked1-6.com/architecture/projects/84-test-deeplink-test.html
And what I should do to get it working.
I've tried to find the answer in several articles but I can't figure it out.
Your .htaccess file should be placed in the directory greenlinked1-6.com. Make sure there are no conflicting rules, like this:
RewriteRule ^(.+)$ $1 [L]
# This line will never be be matched
RewriteRule ^architecture/([a-zA-Z_]+)/(.*).html$ web/index.php?field=1&sub=$1&name=$2
check that u havn't used RewriteBase / just remove & try again...

.htaccess mod-rewrite question

hey there, i have quite some issues with the mode rewrite here is what i use :
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^([^/]*)/$ /creatiiuser.php?user=$1
i would like this link :
http://creatii.artcrew.ro/creatii.php?creatie_thumb=creatie19&user=dee-dee
to look:
like http://creatii.artcrew.ro/dee-dee/creatie19
well this is fine, it works, no problems with it but i want to make a rule for another link
http://creatii.artcrew.ro/categorii.php?numecat=poetry&numesubcat=satire
to look like
http://creatii.artcrew.ro/poetry/satire
how can i do this? what rules must i use?
currently if i access http://creatii.artcrew.ro/poetry/satire
it access the link : http://creatii.artcrew.ro/creatii.php?creatie_thumb=satire&user=poetry
how can i make both links(the first one and the second one) work?
one more thing, i want this link : http://creatii.artcrew.ro/creatiiuser.php?user=Dan to look like http://creatii.artcrew.ro/Dan or if that does not work http://creatii.artcrew.ro/user/Dan
how can i do that?
can anyone help me?
thanks in advance
Given the URL http://creatii.artcrew.ro/X/Y, how is mod_rewrite supposed to know whether X and Y are creatie_thumb and user values or numecat and numesubcat values?
You need to add something to the URL to differentiate these cases.
For example:
http://creatii.artcrew.ro/user/dee-dee
http://creatii.artcrew.ro/user/dee-dee/creatie19
http://creatii.artcrew.ro/cat/poetry/satire
RewriteEngine On
RewriteRule ^user/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^user/([^/]*)/$ /creatiiuser.php?user=$1 [L]
RewriteRule ^cat/([^/]*)/([^/]*)$ /creatii.php?numecat=$1&numesubcat=$2 [L]
Maybe you're too much generic with your rules and you got conflicts.
Try to map this urls
http://creatii.artcrew.ro/creatii/dee-dee/creatie1
http://creatii.artcrew.ro/categorii/poetry/satire
Starting from those sample you can easily map your urls with no conflict on rules
RewriteEngine On
RewriteRule ^creaati/([^/]*)/([^/]*)$ /creatii.php?creatie_thumb=$2&user=$1 [L]
RewriteRule ^categorii/([^/]*)/([^/]*)$ /categorii.php?numecat=$1&numesubcat=$2 [L]
Do some tries :D

Resources