Masking the special pages in mediawiki - php

We are developing a application using mediawiki. we are not fully aware of mediawiki. We have created a special page as mediawiki/Special:Video. But we do not like to view the word Special: in our url. i.e., we would like to view the url as mediawiki/Video instead of mediawiki/Special:Video. If are not aware of mediawiki functions fully. So kindly let us know how to do this url masking in mediawiki. I have tried like this
Options +FollowSymLinks
RewriteRule ^ajax.php($|/) - [L]
RewriteEngine on
RewriteBase /var/www/
RewriteRule ^mediawiki/video$ mediawiki/Special:Video
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(/?[^/]*)$ /mediawiki/index.php?title=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ /mediawiki/index.php?title=$1&actions=$2 [L]
But it is not working

You can rewrite it as follows, no need to use RequestCond
RewriteRule ^mediawiki/Video$ /mediawiki/Special:Video

Related

Changing the URL pattern in PHP

Right now my URL looks like:
https://www.example.com/blogitem.php?id=29
What I want is the user will see the URL in their browser like:
https://www.example.com/blogitem/the-title-of-the-current-blog
This thing is already implemented in Wordpress and other CMS but I am using pure PHP and don't have any idea about how can I implement this feature. Can anyone please help me to implement this?
write this on code .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ blogitem.php?id=$1 [L,QSA]
you need to get title form database instead of id
so it will be like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ blogitem.php?title=$1 [L,QSA]

.htaccess rewrite specific URL segment to a PHP file and then remove the php file from the URL?

I have a wordpress site and a custom build app all on the same URL.
I am looking to redirect all my CMS (custome app) URLs to a certain php controller file. Once redirected I am looking to remove the php file from the URL
e.g. www.website.com/cms redirects to www.website.com/backend.php/cms but the URL continues to display as www.website.com/cms
So far I have the following:
# Handle the custom App URLs
RewriteCond %{HTTP_HOST} ^(www.)?website.com/cms$
RewriteCond %{REQUEST_URI} !^backend.php/cms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ backend.php/cms/$1
# Handle the Wordpress URLs by removing index.php
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
EDIT:
The problem is what I have does not work.
If I go to www.website.com/cms I get a 404.
If I go to www.website.com/backend.php/cms the URL does not change to www.website.com/cms, it stays as www.website.com/backend.php/cms
I am not great at .htaccess but think I am going down the correct route.
Did you try just routing by url:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/cms/(.*)$ /backend.php [L]
#or RewriteRule ^/cms/(.*)$ /yourcms/backend.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
All your magic about 'understanding' the url you do in your cms reading REQUEST_URI.
I ended up fixing this myself by having the following RewriteRule
RewriteRule ^/?cms([A-Za-z0-9\-_\/]+)/?$ /backend.php [L]
RewriteRule ^/?cms /backend.php [L]
Thanks to those that tried to help :)

Friendly URL profile and about using rewrite in htaccess

I have this url
http://example.net/test
but i have need
http://example.net/test/info
I have this code in my htaccess ,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./id.php?u=$1
how to can i used code with like a link
http://example.net/test/info
Ok. We explain it.
Your htaccess:
Options All -Indexes
AddDefaultCharset utf-8
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?$1 [L]
Your php:
var_dump(explode('/', explode('?', $_SERVER['REQUEST_URI'])[0]));
You can use this parts for call (with router) to your routines of site. Implementations of controllers, methods, routers - many and different. I do not know what you doing. I only suggest you choose the right way.

two RewriteRule's for two different but like urls

My .htaccess is
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^api\/(.*)$ api.php?action=$1 [L,QSA]
RewriteRule . index.php [L]
so all requests i receive in my index.php and then parse query string, and one of my pages is "api documentation page" with url http://domain.com/api so i require page about api from templates
and another url is http://domain.com/api.php where i need receive $_GET['action'] and another data with $_POST
so it will work like http://domain.com/api.php?action=start, but i need call it like http://domain.com/api/start or http://domain.com/api/start/ and receive $_GET['action'] - "start"
but this string in my .htaccess doesnt work
RewriteRule ^api\/(.*)$ api.php?action=$1 [L,QSA]
You need to keep RewriteCond before every RewriteRule if you want to apply for all URLs or keep them in a separate rule. Try this .htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /
# ignore all files/directories from all rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^api/(.+)$ api.php?action=$1 [L,NC,QSA]
RewriteRule . index.php [L]
Ah, I've had that problem before, can't remember exactly how it went, but this link seems relevant: https://wiki.apache.org/httpd/RewriteFlags/QSA
The only difference with yours is the slash at the beginning to make the paths absolute and you don't need to escape slashes. E.g.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/([a-z]*)/? api.php?action=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
But none of those differences seem to be the cause of the problem. As pointed out by nubhava, the RewriteCond's only affect the next rule though.
When faced with this kind of situation though, I usually end up using a router, to do the "rewriting" in PHP.
See also Mod-Rewrite or PHP router?
RewriteEngine On
RewriteBase /
RewriteRule ^api/([^/]*)$ /api.php?action=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
work's, http://htaccess.madewithlove.be/ help's me trying different combinations

Removing '&title' from the URL in .htaccess

I'm trying to create shorter urls to some of my pages.
Previously I had a system that URLs were like /index.php?m=page&title=Page-Title
The piece of code I have now allows me to remove the everything 'm=' part. /index.php?m=page in here, the 'page' is a name of different modules, so this part might still change. I want to change the url only from 'page'.
How would I rewrite this so that my URL would be composed only as such:
/page=Page-Title
Would that be even possible since I'm using $_GET in 2 places?
My current .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/?p=$1 [L]
You can have your rules like this:
RewriteEngine On
RewriteRule ^page=([^/]+)/?$ /index.php?p=page&t=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/?p=$1 [L,QSA]

Categories