Ad
Remove Filename From Url With .htaccess
I want to remove file name and extension from url, i have a directory (Blogs) and two files in it (Main_blogs.php) and (Blog.php)
localhost/SikandarIqbal.net/blogs/
when i open Main_blog.php in directory "Blogs" i get the above url which i was able to get with this htaccess file :
DirectorySlash Off
DirectoryIndex disabled
RewriteEngine on
# prevent direct access to PHP files
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php$ - [R=404,L]
# rewrite requests for a directory to index.php
RewriteCond %{REQUEST_FILENAME}/Main_blogs.php -f
RewriteRule ^.*$ $0/Main_blogs.php [L]
and when i open a specific blog from Main_blog.php the url becomes
localhost/Sikandariqbal.net/Blogs/Blog.php/My-Blog-name
what i really want is to be like something
localhost/Sikandariqbal.net/Blogs/My-Blog-name
Remove the filename Blog.php between /Blogs/ and /My-Blog-name
please help!
thanks
Ad
Answer
You need an additional rule for this:
DirectorySlash Off
DirectoryIndex disabled
RewriteEngine on
# prevent direct access to PHP files
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php$ - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Blogs)/page/(\d+)?$ $1/?pn=$2 [L,NC,QSA]
# rewrite requests for a Blogs/Blog.php/<url>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Blogs)/([\w-]+)/?$ $1/Blog.php/$2 [L,NC]
# rewrite requests for a directory to Main_blogs.php
RewriteCond %{REQUEST_FILENAME}/Main_blogs.php -f
RewriteRule ^.*$ $0/Main_blogs.php [L]
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad