I am working on an e-commerce project , but i am facing two problems.
first, when i click on sub category link such as classic shoes
supposed that mysite.com/classic-shoes.php open
now i need to make classic-shoes.php file and file to every sub category and that is nonsense
second, i want my url to be like that
https://www.jumia.com.eg/mobiles-tablets/
not having .php in the end of the link..
forgive me on my bad english but i hope that you understand my problem, thanks in advance
To remove the php extension from url you can use htaccess file to rewrite the rule
create .htaccess file in root directory of your project — use sublime text or any other text editor to create if you are unable to create .htaccess file.
put the rule below in this file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z_-]+)$ $1.php [L]
For more reference:
http://www.htaccess-guide.com/
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Related
I've got a CMS which I created by myself and I have an external link, which shows the web created by the user.
The link is: http://localhost/CMS/www/users_template/{user_name}
Is there any possibility to change the link and make it:
http://localhost/CMS/{user_name}
but it should still show the web page without any errors?
I think I should edit my .htaccess file, but no idea how to do it. I have never edited the .htaccess file before.
This is a duplicate.
Please view .htaccess: removing part of url path and stay at base
RewriteEngine On
RewriteBase /CMS/
RewriteRule ^www/users_template/(.*)$ $1 [L,R=301,QSA]
Im trying to build a Image sharing site(Mostly for fun).
so my current predicament is how to make any image i have redirect to a php file of the same name.
I.E
www.example.com/folder/fuzzycat.jpg
Should goto
www.example.com/folder/fuzzycat.php
That way i can css and JS it to my heart's content.
i'm trying to do it with the .htaccess file so i'm not having to implement some framework or anything that would slow my site.
Thank You.
In the /folder/.htaccess, you can use:
RewriteEngine on
RewriteRule ^(.+)\.(?:gif|png|jpe?g)$ $1.php [NC,L]
I am currently building a website and it hasn't gone online, I am using wamp server 2.4. I need to remove the sub directories so as to not let out the structure of my directories, I have a test site with the following folders: includes and sub.
The links to be accessed are in sub so if the user clicks on a link that goes to sub/link.php, the url shows localhost/sub/link.php..I would like it to show localhost/test/link/ without the sub showing. So far I have googled mod_rewrite in Apache, learnt about it but still unable to remove sub-directory. All I have achieved is to remove the file extension(.php).
I have searched here on Stack Overflow but the answers are not helping maybe because they use online hosted websites. The link.php has no variables, it's a simple php file that could echo stuff but it's not using any GET/POST variables.
This is the html code, i have intentionally written one 't' in 'http'..though in the code it is two..
Link
RewriteEngine On
RewriteRule ^sub/(.*)$ /$1 [L,R=301]
Take a look at this site, it's hosted on wordpress and every link that you go to is shown without any subdirectories, it's just got one trailing slash after the url, is it possible to achieve that on apache?
http://www.afdar.com
Try this in your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/test/sub/
RewriteRule ^test/(.*)$ /test/sub/$1 [QSA,L]
It will rewrite URLs:
http://localhost/test/sub/link.php to http://localhost/test/link.php
http://localhost/test/sub/another.php to http://localhost/test/another.php
On a php web page, i'm displaying an html5 player which plays an mp3 track, and there's a download button next to that. I want to mask the download link only, so visitors will not be able to see the directory tree of my server (www.example.com/content/plugins/audio/downloads/test.mp3). I want to change the link to something more simple and smaller like (www.example.com/download/test.mp3) without changing the folders structure of my server.
I'm not sure if it is an .htaccess or PHP thing.
Thanks in advance.
With .htaccess you would need the following rewrite rule:
$ pwd
/var/www
$ cat .htaccess
RewriteEngine on
RewriteRule ^/download/(.*\.mp3) /content/plugins/audio/downloads/$1 [NC]
It will match all http://yourdomain.com/download/….mp3 requests and redirect to http://yourdomain.com/content/plugins/audio/downloads/….mp3
If you want your .htaccess to work from inside a subdirectory, use RewriteBase:
$ cat subdirectory/.htaccess
RewriteEngine on
RewriteBase /subdirectory
RewriteRule ^download/(.*\.mp3) content/plugins/audio/downloads/$1 [NC]
i.e. http://yourdomain.com/subdirectory/download/….mp3 to http://yourdomain.com/subdirectory/content/plugins/audio/downloads/….mp3
I want to hide file extensions from a URL like
if the current URL is
http://localhost/salsgiver/administrator/menus.php?sect=about
then the new one will be exactly
http://localhost/salsgiver/administrator/menus/sect/about
and so on, similary if the current URL is
http://localhost/salsgiver/administrator/products.php?id=1
then the new one will be exactly
http://localhost/salsgiver/administrator/products/1
Or some thing different, so that the viewer could not guess the exact URL.
I searched Google and found some matter on
http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html
and also used, but it does not work and the mod_rewrite module is also enabled in Apache. And when I create the .htaccess file to secure a folder from all using
deny from all
it works fine.
You could do this, but mod_rewrite is much easier to use if you use a single index.php which then chooses which file to open (products.php or menus.php)
For a single index file:
RewriteRule ^(.*)$ index.php?query=$1 [L]
For multiple files:
RewriteRule ^(.*?)/(.*?)/(.*?)$ $1.php?$2=$3 [L]