SEF url without name with core php and .htaccess - php

I want to make SEF url In that i want to remove file name also from the url.
my site is in the core php, I manage to remove the extension from the url but didn't have idea that how to remove the whole file name from the url.
As i searched on google i got this code for the .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have no idea that how to write header in php so it goes in related file but don't show the file name in url.
<a href='http://mysite.com/edit/user/2/1'>click</a>
Now if i click on above link it does goto edit.php with url "mysite.com/edit/user/2/1",
so from this how can i remove file name that is "edit".
Thanks in advance

Why? Isn't that a SEO friendly and user friendly URL? Why would you want to make it un-user fiendly? But anyway my guess is that you want /user to point to /edit by the looks of it:
RewriteRule ^/?user/*$ /edit.php?type=user&%{QUERY_STRING}
Though you will be making your site worse by using this and adding uneeded complexity to not only site maintenance but also user navigation.

Related

Removing page extension with .htaccess bugs Facebook Open Graph

I researched for removing page extensions (Ex: /page.php to just /page) and I found this article: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
So, I inputed this code into my .htaccess file. It really worked, but when I paste/type my index link at Facebook status with no trailing slash at the end, the Open Graph kinda bugs. There's no thumbnail, no right title and description.
Check it: http://www.aftercolors.com.br
Would the solution be remove the code from .htaccess and create subfolders with index files to have the pages without extension?
That's the code of my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
You can try this one for just single link:
RewriteRule ^page page.php [L]
If you want just to redirect that one simple file. It's better to use id's to get bigger spectrum.

search engine friendly blog urls

Hey i am in the process of making a blog for my site, i have decided to make my own rather than use a 3rd party, however i cannot figure out how to make the url's seo friendly atm they are like this /blogpost.php?id=15 however i want it to be /the-title is there any way to do this without htaccess? atm i am using this to make the urls'
echo '<a href="blogpost.php?id='.$row['id'].'">';
Then i am using _GET to get the id and then get the information from the database, i could replace id with name but that gives me /blogpost.php?title=The-Title
Thanks for the help.
In your htaccess you put something like this (if using apache)
RewriteEngine On
#ignores real files
RewriteCond %{REQUEST_FILENAME} !-f
#ignores real directorys
RewriteCond %{REQUEST_FILENAME} !-d
#ignores symlinks
RewriteCond %{REQUEST_FILENAME} !-l
#forwards the request onto index.php with the orignal querystring still intact
RewriteRule (.+) index.php?url=$1 [QSA]
Then any thing after the / will be forwared to the $_GET['url'] in index.php.
Then in index.php you can have a bootstrap class that will explode this by /.
Then you can load the appropriate class based on the first element in this array.
For example if the url was /articles
it would load the articles controller based on the /articles
Or if the url was /articles/about-something
The articles controller will load the article by fetching an article from the database with the about-something slug.

htaccess need help rewriting url

I've been trying to rewrite my URL's with a htaccess file.
My project is using my index.php as it's basic controller.
I fetch the pages from the database with the get-value "naam".
Example:
localhost/YourDesigns/YDCMS/index.php?naam=home (this shows the homepage)
localhost/YourDesigns/YDCMS/index.php?naam=about (this shows the about page)
Now i want to rewrite the URLS to be shown like this:
localhost/YourDesigns/YDCMS/home (this shows the homepage)
localhost/YourDesigns/YDCMS/about (this shows the about page)
I have done some htaccess stuff myself and i've successfully removed the "index.php" from the url, but the "naam" still remains.
How do i remove this?
This is my current htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /YourDesigns/YDCMS/index.php?naam=/$1 [L]
Thanks in advance :)
I think your way to see the process it's not totally right, if you want to show the url like you say localhost/YourDesigns/YDCMS/home you have to first replace the url inside your html content to that format, then by using a RewriteRule you call the correct path internally:
RewriteRule ^desired_url_path/([a-z0-9\-]+)$ /base_url_path/index.php?naam=$1 [L]
this way when an user click on a link the Apache server will use the above regex to convert the url by a rule that basically says : everything after the base url is aparameter value to be passed on the index.php.
Naturally the regex can be modified to suit your needs, the one i've written above it's a basic string pattern.

Redirect example.com/out/1234 to another URL

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

something messy with .htaccess while using php include

I am currently working on a web application where i want to give user access to their profile by typing www.mysitename.com/username this is working fine with .htaccess but i also want the user to access other pages with clean urls by redirecting
http://www.mysitename.com/song-type-one.php?song=xyz to
http://www.mysitename.com/song-type-one.php/song/xyz
i used the rewrite rule like this
RewriteRule ^(.*)$ ./song-type-one.php?song=$1
RewriteRule ^lok-songs/(.*)$ .song-type-one.php?song=$1
if i type the clean url now in the browser only my main content is loaded the css, javascript and my php include are not loaded. there might be something wrong with my .htaccess whats the best way to achieve all rules i want with .htaccess ?
Try adding this before it:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
If the file exists on disk it won't do your rewrite rule allowing the JS and images to be loaded normally.

Categories