I'm trying to redirect a file using a fake folder, but I can not get it to work properly. I've been searching and trying different things but none of them worked out for me.
How my current URL looks like:
/new-weblog.php
How I want the URL to look like:
/weblogs/new-weblog.php
I do not want to redirect ALL urls to have the fake /weblogs/ folder. Only just for that one specific file.
Thank you in advance.
This doesn't qualify as an answer, however, this is a good tutorial that will give you the desired solution you're looking for and teach you about htaccess commands while you're at it.
Here's the link: https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
Related
I have a folder where I will save all the posts from a blog. It will be useful for me to have each file with a number. This way I can have things organized and easy to find. But the user does not need that number and it would be better to have a cleaner URL without it.
I am familiar with RewriteEngine rules in the htaccess. But I do not know how to do it in this case.
For example: I would like to have in my local folder and in the server:
www.example.com/blog/4-theTitleOfthe4post
www.example.com/blog/5-theTitleOfthe5post
and so on…
I would like the user to have something like:
www.example.com/blog/theTitleOfthe4post
www.example.com/blog/theTitleOfthe5post
and so on…
Is it possible to have a clean url without the number of the post? and still have the files organized internally and in the server with the number of the post?
Yes.
RewriteRule ^(blog/)(\D*(\d+)\D*)$ /$1$3-$2
https://regexr.com/4kjth
I'm trying to create friendly url for my site but with no success :(( and i have two questions
The first is:
How to change the url from domain.com/page/something.php to domain.com/something
And the second is:
Will the changes make duplicate content and if how to fix the problem.
Thank you for your time,
Have a nice day
Check out the official URL Rewriting guide: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
You'll be using the simplest use case, Canonical URLs. Assuming you have no other pages that you need to worry about, you can use a rule like this: (note: untested, your usage may vary)
RewriteRule ^/(.*)([^/]+)$ /$1$2.php
While that example might not exactly work for your use case, hopefully reading the guide and my example will help you get you on your way.
I've been searching around and tried many different ideas to fix the state of a URL for my client, but have had no joy.
The URL currently looks like this:
website.com/folder1/folder2/folder3/page.php
My client wants this to be showing much like the other links on the website as so:
website.com/page
I'm fine with removing the .php that's simple enough and is already written into my .htaccess file. It's just removing the 3 directories from the URL is what I cannot work out.
Before anyone asks about moving the file to a higher directory, I'm afraid this cannot be done as everything needs to be down in this 3rd directory for this page.
I believe my latest attempt is about the closest I've got to solving this, if anyone could point out my mistakes and a solution it would be much appreciated:
RewriteRule ^/folder1/folder2/folder3/(.*)$ /page$1 [L,R=301]
EDIT:
After researching more today, I think I may have confused people with this question. I think what I should have said is that I need to mask the URL, hiding the 3 directories, and showing just the domain and the page itself.
I still seem to be hitting a wall with masking too. Any advice?
After a whole weekend (and quite a bit of the week between working) I finally managed to succeed with what I wanted.
The site now displays as required:
website.com/page
Which has been redirected and masked from:
website.com/folder1/folder2/folder3/page.php
The piece of code required in the .htaccess is as follows:
RewriteRule ^page$ /folder1/folder2/folder3/page.php
Looks like I was being stupid before and had the syntax backwards, but all is well now and I'm allowed to sleep :)
Hope this helps anyone else in future with this sort of problem!
For example, I want:
http://site.com/cool.php?page=woohoo
http://site.com/cool.php?page=yoyoyo
To show this in the browser:
http://site.com/woohoo/
http://site.com/yoyoyo/
How do I do this?
Check this answer: https://stackoverflow.com/a/8446690/995958
It gives a nice way to do exactly what you want to do.
Other answers are useful too if you have problems with the confirmed one.
I would like to find a way for users to be able to type their username after my domain name to access their public profile page.
For example, if you type youtube.com/username it shows that user's channel page. The resulting page is the same as youtube.com/user/username.
So with my website, I have mydomain.example/users/profile.php?name=username
It's a bit more complicated, with PHP and variables and subdirectories and everything... I would like that same page to display when I type mydomain.example/username
I really have no idea where to start with this, but I suspect it would be something in the .htaccess file, which I do have access to.
Thanks for any help!
edit: sorry this is a few days old, I've been having some other troubles and I haven't been able to test it until now. Anyway, it isn't working...
Just to recap, I want mydomain.example/username
to filter to
mydomain.example/users/profile.php?name=username
Thanks..
edit2: I found this also on stackoverflow... link text i tried tweaking that, and what was mentioned here a few days ago... but it still won't work. Any ideas?
I also keep finding pages that recommend the strategy this guy used: link text but it looks like that would cause more problems than it's worth.
Any ideas?
RewriteEngine on
RewriteRule ^user/(.*)$ profile.php?name=$1 [NC,B,QSA]