how to create Short Url in Mediawiki? - php

My mediawiki's localproject name is "wiki_test".and i use following code for localsettins.php file
$wgScriptPath = "/wiki_test";
$wgArticlePath = "/wiki/$1";
require_once("$IP/extensions/ShortUrl/ShortUrl.php"); //
and create one file in the root(means in my project folder) .htaccess file.and put following code in that
RewriteEngine On
# Short url for wiki pages
#RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mediawiki_test/index.php/ [L]
# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/mediawiki_test/index.php [L]
and try for short url but give error like"Object not found!". so plz give me idea........

If you are placing your .htaccess in mediawiki_test directory then this code should work:
RewriteEngine On
RewriteBase /mediawiki_test/
RewriteRule ^index\.php$ - [L]
RewriteRule ^ index.php [L]

Related

How do I remove subfolders an image's URL using ".htaccess"?

How do I remove subfolders names from URL?
For example:
mywebsite.com/wp-contents/uploads/2019/02/image.jpg
mywebsite.com/wp-contents/uploads/user/demo/2019/02/image2.jpg
Then the same URL without the subfolder's name:
mywebsite.com/uploads/image.jpg
mywebsite.com/uploads/image2.jpg
INFO: I can only use .htaccess to achieve this.
Try this rules in your .htaccess file
RewriteEngine On
RewriteRule ^uploads\/image\.jpg$ /wp-contents/uploads/2019/02/image.jpg [L]
RewriteRule ^uploads\/image2\.jpg$ /wp-contents/uploads/user/demo/2019/02/image2.jpg [L]
another rule for all /uploads/image***.jpg to /wp-contents/uploads/2019/02/image***.jpg
RewriteEngine On
RewriteRule ^uploads\/(.*)$ /wp-contents/uploads/2019/02/$1 [L]

Static url does not redirect to the requested page

I have a question regarding the .htaccess file.
I have rewritten a dynamic url in a static one as following:
www.mysite.com/index.php?lang=IT
in
www.mysite.com/it
using this rewrite rule:
RewriteEngine On
RewriteRule ^it/([^/]*)\.html$ /index.php?lang=$1 [L]
So far so good...
Now I need to create another static url for a dynamic url which redirects to the product description
www.mysite.com/product_details.php?id=1485
The rule inserted in the .htaccess is:
RewriteEngine On
RewriteRule ^it/prodotto-([^-]*)-([^-]*)\.html$ /it/product_details.php?id=$1&lang=$2 [L]
Unfortunately if I click on the related link I cannot reach the requested page; but if I comment the first rule like this
#RewriteRule ^it/([^/]*)\.html$ /index.php?lang=$1 [L]
then I can see the page.
Do you know how to solve this issue?
Assuming that lang equals to language you want the script do like so?
RewriteEngine On
RewriteBase /
RewriteRule ^it/([^/]*).html$ /index.php?lang=$1 [L]
RewriteRule ^it/prodotto-([^/]*)-([^/]*).html$ /it/product_details.php?id=$1&lang=$2 [L]
this will do
yoursite.com/it/$1.html
and
yoursite.com/it/prodotto-$1-$2.html
?

htaccess rewrite url folder/file to folder/file.php

I want ajax/file address to be redirected to ajax/file.php using .htaccess. I created a .htaccess file like below but that gives a 500 Internal Server Error.
RewriteEngine On
RewriteRule ^ajax/(.*)$ ajax/$1.php [L]
An additional information is that my website is working under a sub-folder. (localhost/myproject) RewriteRule ^ajax/(.*)$ /ajax/$1.php [L] redirects url to (localhost/ajax/file.php) instead of (localhost/myproject/ajax/file.php
Problem is that .* in your regex also matches file.php.
Use your rule like this:
Options -MultiViews
RewriteEngine On
RewriteRule ^ajax/([^./]+)/?$ ajax/$1.php [L]

How to change php urls on my website?

Is it possible to somehow change my website links from:
domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test
into this:
domain.com/category-test
domain.com/section-test
domain.com/news-test
Thanks and have a good day!
You can achieve this using .htaccess and mod_rewrite. You'll need to create a .htaccess file with the following contents:
RewriteEngine On
RewriteBase /
RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1
Now, accessing domain.com/category-test/ will take you to category.php?tag=test.
If you'd prefer to have slashes instead of dashes, you can use:
RewriteRule ^category/([^/]+)/?$ category.php?tag=$1
RewriteRule ^section/([^/]+)/?$ section.php?tag=$1
RewriteRule ^news/([^/]+)/?$ news.php?tag=$1
RewriteRule ^category-([a-zA-Z0-9]+)$ category.php?tag=$1 [NC,L]
RewriteRule ^section-([a-zA-Z0-9]+)$ section.php?tag=$1 [NC,L]
RewriteRule ^news-([a-zA-Z0-9]+)$ news.php?tag=$1 [NC,L]
In "category.php" file get the tag $_GET['tag'];

HTACCESS file not working for Clean URL

Folder where page.php resides: http://www.MySite.com/index/product-details/
URL: http://www.MySite.com/index/product-details/1276/Electric-Circuit-Breaker
item_id parameter: 1276
item Title: Electric-Circuit-Breaker
I just need page.php to read 1276 as item_id. This is my failed attempt at an htaccess file:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)$ page.php?item_id=$1
RewriteRule ^([a-zA-Z0-9]+)/$ page.php?item_id=$1
Please tell me where I'm going wrong. Htaccess file is in product-details/ folder
Given the .htaccess file in question is on the folder /root/index/product-details/ aka http://www.MySite.com/index/product-details/:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /index/product-details/
RewriteRule ^index/product-details/([0-9]+)/(.*)$ page.php?item_id=$1 [NC,L]
It will capture the id only and internally redirect.
If the above doesn't work change the rule into:
RewriteRule ^([0-9]+)/(.*)$ page.php?item_id=$1 [NC,L]

Categories