Currently, a user's timeline can be accessed on my site using localhost/dateapp/timeline?profile=user1571502747. Here user can later manually change their username from user1571502747 to anything they like for easy access. Now what I want is if someone opens localhost/dateapp/user1571502747 (or mysite.com/user1571502747 when live), it automatically redirects and opens the timeline of user user1571502747 or say it redirects to localhost/dateapp/timeline?profile=user1571502747. But I am not being able to figure out a way to do so. Currently, when trying to access that displays no page with page not found browser error. Of course I have haven't put anything for it yet so its natural to get this error. Can anybody guide me on doing this? Facebook does this, for reference. Thanks in advance.
UPDATE: If anything needs to be done in .htaccess file then my current .htaccess has the following.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,END]
You can use .htaccess for this.
Try adding this to your .htaccess file in your root directory
RewriteEngine On
RewriteRule ^([^/]*)$ /timeline?profile=$1 [L]
Related
Trying to set up a simple example/url/system thing using htaccess, which I haven't done for many many years admittedly, and all was working fine until a file actually exists, at which point it no longer redirects to index.php?var=String, it simply displays String.php.
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?vfirst=$1&vsecond=$2&vthird=$3 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?vfirst=$1&vsecond=$2 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?vfirst=$1 [NC,L]
My example is /users/edit-profile/. Before I had created users/edit-profile.php, the server would take me to index.php and display my 404 page (as well as debug confirming vfirst - vthird were set and read correctly) - however as soon as I created a blank edit-profile.php, the blank page is all that comes up instead of index.php. I have the PHP covered to include users/edit-profile.php if it exists and is the URL chosen, but I don't think its getting that far.
Regex/htaccess was never my thing but even I think it's looking light and I must be missing a line that basically tells it to ignore whether the file exists, capture the variables and go to index.php. Any help?
I am not sure that I understand your question correctly, but I would try to answer as far as I understand.
So, if you need do display some page, when a non-existent page is called, then try to use this script:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . somepage.php [L]
If you need to do something else, then please let us know, and maybe me or someone else would provide necessary information.
I've run into a problem I just cant solve that is:
I have a proxy script running on FileHound.co.uk
The htaccess file contains:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /?load=%{REQUEST_URI} [L,QSA]
I need to be able to redirect certain URL such as this:
filehound.co.uk/?load=/torrent/9392320/%5Ba-destiny%5D_toriko_-_135_(1280x720_hi10p_aac)_%5Bde83bd3d%5D.mkv
I want to prevent the link from displaying its destination instead being redirected to a page to i.e. /DMCA/DMCA.html
There are many links that need redirecting in a similar way. As I say its a proxy script and so I cant remove the page or material myself.
Any help would be much appreciated...
If you put all the links that need to be redirected in a database then you can query that table and redirect if it exists something like this (pseudo code):
# if (url in db)
# redirect /DMCA/DMCA.html
Don't forget to sanitize your input, don't want sql injection ;)
I know theres a lot of posts about redirects but this is a little different (I think).
Basically I want my outlinks to be example.com/out/1234 and I want them to go to a php that looks up the URL 1234 if referenced to in MySQL and the php header redirect to that URL.
The problem Im having is passing 1234 to a page. I know how if it was out.php?q=1234 but I want it to be /out/1234
Does there need to be an index file within an /out directory that also has a htaccess to rewrite it?
If so, any ideas what the regex need to be to do this? I have seen a few sites doing this and I cant work it out.
htaccess file in your document root, you can try adding:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?out/(.*)$ /out.php?q=$1 [L]
Replace the /out.php with whereever your php script for handling the URL is
i'm working on a script and I want to make the links such as www.mysite.com/signup. this link for registration. www.mysite.com/user/username and this link for user's profile. the links without any php extension. also when someone request link such as www.mysite.com/signup.php should redirect him to www.mysite.com/signup
.my .htaccess
RewriteEngine On
RewriteRule ^/?([a-z]+)$ $1.php [L]
with this, all links are working fine, but when I access the user's profile such as
www.mystie.com/profile/username
I get this error
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
my question: what code to add to let that link works fine?
thank you
Your routing requests blindly to php files, this doesn't have anything to do with your issue:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^/?([a-z]+)$ $1.php [L]
Now you need to add a rule to route profiles, since you don't have a rule for it, your profile links aren't going to work. So something that looks like:
RewriteRule ^/?profile/(.*)$ /profile.php?username=$1 [L]
Replacing profile.php with whatever script generates profiles and the username= with whatever _GET param the script looks for for the username.
Ok I solved the problem
big thanks to all who tried to help me and especially Jon Lin :)
this is the code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.*)$ profile.php?username=$1 [L]
my profile.php
$username = $_GET['username'];
$info = fetchUserInfo($username);
echo $info['username'];
echo $info['userid'];
hope also help some people having same problem
You want to read in the manual for mod_rewrite about the two directives 'RewriteLog' and 'RewriteLogLevel'. Using those you can learn to understand how the rewriting engine processes the requests by seeing all steps in a log file.
I have a site which I have converted to use cms made simple. It works perfectly and I have the friendly urls working fine too. My issue is with a little script I wrote myself and how best to integrate it. The script is a gallery script, it reads a directory and outputs a formatted gallery in html. I was planning on making it a user defined tag in cms made simple but I hit a small snag.
The gallery script needs to be able to read in two values from the url groupId and showpage.
If I am using freindly urls then the cms and use the tag I hit a snag as the cms tries to find an actual page at "www.mysite.com/gallery/mygroup/2" and then throws a 404.
basically I need
http://www.mysite.com/gallery/photogroup/2
rewritten to
http://www.mysite.com/gallery.php?groupId=photogroup&showpage=2
UPDATE
Follwoing Yuri's advice I added his rule to the htaccess. But I have hit another snag.
So for instance if we go to
http://www.mysite.com/gallery/photogroup/2
then Yuri's rule should take effect. But that path is also a correct physical directory on my site coincidentally. Is there a way to have the rewrite rule take effect instead of bringing me to a white screen browsing the files in the directory or to the forbidden screen if I have indexes turned off which I do.
Below is my htaccess
php_flag magic_quotes_gpc Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1
RewriteRule ^gallery/(\w+)/(\d+)$ gallery.php?groupId=$1&showpage=$2 [QSA,L]
So, did you try to write in .htaccess something like this?
RewriteEngine On
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d
RewriteRule ^gallery/(\w+)/(\d+)$ gallery.php?groupId=$1&showpage=$2 [QSA,L]
sounds like a "module" to me. Maybe this Make your module use clean URLs