URL Rewriting-Page display - rewrite rule in .htaccess - php

For URL Rewriting, i have got the output for static URL
But , for dynamic URL , i am getting partial output only.
I have placed the .htaccess file in the root directory only.
Here is the code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/price/([0-9]+)/?$ booking.php?price=$1
What will be the solution ?

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/([0-9]+)/?$ booking.php?price=$1
RewriteRule ^booking/([0-9]+)/([0-9]+)/?$ booking.php?price=$1&pass=$2
You really want to customise your code for these though so as to be able to use general rules, rather than converting specific paths to use $_GET.

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/([0-9]+)/?$ booking.php?price=$1
RewriteRule ^booking/([0-9]+)/([0-9]+)/?$ booking.php?price=$1&pass=$2
For images and Css you need to define your base folder in htaccess file as
RewriteBase /~your folder/

Related

.htaccess rule for language detection in subdirectory

I have an URL that is https://www.myurl.com/subdir/language/login.php .
The "language" parameter is not an existing subfolder. The folder structure is:
root/subdir/.htaccess
As you can see the .htaccess file is located in https://www.myurl.com/subdir/.htaccess
I would like to do a .htaccess Rewrite Rule in order to change the called uri:
https://www.myurl.com/subdir/en/login (without .php)
to:
https://www.myurl.com/subdir/login.php?lng=en
My current apporach is:
# MultiViews must be disabled for the rewrite to work
Options -MultiViews
# Turn on the rewriting engine
RewriteEngine On
RewriteBase /subdir/
RewriteRule (en|de)(/login)$ login.php?lng=$1 [L]
But when I call the URI https://www.myurl.com/subdir/en/login I get an http error code 404.
Yes thats it! One more question, what if the scenario is all the same, but I would like to get the (en/de) in front of /subdir/ ? So the url would be myurl.com/en/subdir/login:
In this case rule must be placed in site root .htaccess instead of subdir/.htaccess with this rule:
Options -MultiViews
RewriteEngine On
RewriteRule ^(en|de)/(subdir/login)/?$ $2.php?lng=$1 [L,QSA,NC]

How to implement Apache Rewrite Rule correctly?

Following is my rewrite rule code written in the .htaccess file placed in the
beta1
folder.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /beta1/
RewriteRule /(.*) read.php?post=$1 [R,NC]
Currently the URL is:
http://localhost/beta1/read.php?post=Happy+Mother+Day.
And i want the link to appear like:
http://localhost/beta1/Happy-Mother-Day.
Do I also need to change the way "read.php" extracts data from the database? If yes, then how?
Do i also need to make any changes in the "read.php" file?
The rewrite code above is not working.
hey please try this rule
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([A-Za-z0-9-_]+)?$ read.php?post=$1 [NC,L]
And read.php file
echo str_replace('-',' ', $_GET['post']);

it is possible to add folder prefix in for all images path?

I've a drupal 8 website and it contents contains some url like this
http://localhost/sites/default/files/inline-images/magento.png
this link is come from a block which was saved in db /sites/default/files/inline-images/magento.png
I want to convert all images into http://localhost/folder/sites/default/files/inline-images/magento.png
can i do this by .htaccess mod rewrite?
Did you try something like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)\.(png|jpg|gif|svg)$ /folder/$1.$2 [L,R=301]
</IfModule>
You can try removing this part R=301 and leave only L.
At the top of your htaccess root add the following :
RewriteEngine on
RewriteRule ^/?folder/sites/default/files/inline-images/(.+\.png)$ /sites/default/files/inline-images/$1 [L,NC]
This will internally redirect /folder/sites/default/files/inline-images/foo.png to /sites/default/files/inline-images/foo.png .

rewrite url doesn't include layout?

I'm currently trying to make SEO friendly url's for my website using this script:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^show/([0-9]+)/$ show.php?phto=$1
RewriteRule ^index/$ index.php
So i've tested some things, and i've came up with these problems:
When i visit my website : blalba.com/index/ my layout file wouldn't include/show up. (using an layout.inc.php header/footer system)
Also how can i make it that the user can visit it with index and index/
I'm not so good at this..
Grz
Change your rule with this code (to make trailing slash optional):
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^show/([0-9]+)/?$ show.php?phto=$1 [L,QSA,NC]
RewriteRule ^index/?$ index.php [L,QSA,NC]
Also make sure for including style, js, images etc always use absolute path i.e. it should start with / or http://.

Create .htaccess Rewrite rule same as wordpress

I am Creating Rewrite Rule in .htaccess
I have some issue i am creating Rule like wordpress but i didnt get correctly
The Rule which i am writing is below
`RewriteRule projectDir/(.*)/(.*)/(.*)$ index.php?module=$1&action=$2&id=$3`
In this ReFacta is my Project Directory
The Url Which i want it same as like below
`http://localhost/projectDir/user/edit/5`
Any idea Friends ?
You are nearly correct. what is wrong in your code, you don't have specified RewriteBase
Options +FollowSymLinks
RewriteEngine on
RewriteBase /projectDir
RewriteRule ^(.*)/(.*)/(.*)$ /index.php?module=$1&action=$2&id=$3 [L]

Categories