Pagination and htaccess troubles - php

I have some trouble with URL Rewriting, here is my .htaccess file :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^insertCom/([0-9]+)$ /routine/Commentaires/insert.php?art=$1 [L]
RewriteRule ^projets\.php$ /vue/projets.php [L]
RewriteRule ^projet/([0-9]+)$ /vue/project/ListeEpisodes.php?serie=$1 [L]
RewriteRule ^p/([0-9]+)$ /index.php?p=$1 [L] (4)
RewriteRule ^([a-z0-9-]+)$ /vue/article.php?article=$1 [L]
Like I said in the title, I have issues with pagination.
When i use
mywebsite/p/2
it works perfectly but when I try :
mywebsite/p/30
I am redirected to home.
30 is not a random number, it's the last page.
But surprisingly when I want to go to
mywebsite/?p=30
It works !
Moreover, i tried to change (4) to this:
RewriteRule ^p-([0-9]+)$ /index.php?p=$1 [L]
And when I tried to go to
mywebsite/p-30
It worked!
How can you explain this? And how Cain use the /p/XX format?
Thanks in advance
Plot twist: All of this happened because of web browser's cache!
Sorry for bothering you...

Sorry about that, but I discovered the solution by simply clearing my browser's cache...
I feel so dumb...

Related

htaccess: three variables and two different pages

I am currently trying to figure out how to create an htaccess file that will allow me to perform the following, however I have searched everywhere, and on stackoverflow but I cannot find a solution.
I have an existing site, with a directory /brands/, and an htaccess file setup so that putting anything after brands e.g. /brands/diesel redirects to /brands/index.php?brand=diesel. What I now need to do is redirect anything further in the URL to a seperate page ( in the same directory ), for example /brands/diesel/jeans/male will redirect to inner.php?sear=diesel&t=jeans&g=male
I have tried the following with no success:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ inner.php?sear=$1&t=$2&g=$3 [L]
Anyone who is competent at writing htaccess files will probably be able to spot what is wrong immediately, but unfortunately I am not great with these.
Any help would be greatly appreciated.
I think you might have to setup RewriteBase.
RewriteBase /brands/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ inner.php?sear=$1&t=$2&g=$3 [L]
Try these rules
RewriteEngine On
RewriteBase /brands/
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/?$ inner.php?sear=$1&t=$2&g=$3 [L,QSA]
RewriteRule ^([^/.]+)/([^/]+)/?$ inner.php?sear=$1&t=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ inner.php?sear=$1 [L,QSA]

htaccess multiple parameters rewrite rule

I know this problem is over asked, but couldnt find anything fitting with my problem.
I'm currently creating a website, and my url are like :
www.foo.com/
or www.foo.com/index.php.
They can take 1, 2 ,or three different parameters like
www.foo.com/index.php?page=Home&lang=en&article=1
What i'd like is an url like
www.foo.com/Home/
or www.foo.com/en/Home
or www.foo.com/Article/1
or www.foo.com/en/Article/1
The page parameter is required, other two are not..
I cant have anything working for me... Any help would be greately appreciated
Thanks a lot !
Better to have separate clean rules. Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^([a-z]{2})/([^/]+)/?$ /index.php?page=$2&lang=$1 [L,QSA]
RewriteRule ^([a-z]{2})/([^/]+)/([0-9]+)/?$ /index.php?page=$2&lang=$1&article=$3 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&article=$2 [L,QSA]
Try something like this
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$ index.php?param1=$1&param2=$2&param3=$3

php how to replace ?page=1 to 1

I'm just wondering how other websites replace there get variable.
example:
http://www.example.com/page.php?page=1
replaced:
http://www.example.com/page/1
indeed, just what ssx said.
You need a .htaccess file in the root of the website, with some content that looks like this (i use this one)
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([\(\)\|a-zA-Z0-9_-]+)/([0-9]+)/?$ /index.php?ext=$1&cat=$2&name=$3&urlID=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([\(\)\|a-zA-Z0-9_-]+)/?$ /index.php?ext=$1&cat=$2&name=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/p=([0-9]+)/?$ /index.php?ext=$1&cat=$2&p=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /index.php?ext=$1&cat=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /index.php?ext=$1 [L]
I'd say take a look at an answer I provided someone else a while back. I'd type it all out here again or copy and paste it but the link is much easier.
PHP dynamic DB page rewrite URL

.htaccess clean url with more than 3 paramenters

I am new to .htaccess and I seem to be having some problems getting it to clean up the url for me.
I have
site.com?p=article&id=3&read=article title
I am able to get the first variable to work ok like site.com/articles. but when I try to go further the server is saying it cant find it. I have tried several methods none of which seem to be working.
RewriteRule ^([a-zA-Z0-9]+)$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?p=$1
this above is working
I have tried
RewriteRule ^([a-zA-Z0-9-z\-]+)(/([a-zA-Z0-9-z\-]+))?/?$ index.php?p=$1&i=$2
and
RewriteRule ^([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/?$ index.php?p=$1&i=$2&read=$3
the last 2 are not working. help please. Thanks
Let's try something like this?
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?p=$1&id=$2&read=$3 [L]
%{QUERY_STRING} is what you are looking for.
this is what I use for a similar situation:
RewriteRule ^/(.*) /index.php?r=/$1&%{QUERY_STRING} [L]

mod_rewrite with ? in the original URL like YouTube

Ok I want to simulate the YouTube URL and redirect it to my real URL. Reason being is I used a random string to make video ID's so they aren't guessable by sequence.
I have the links as so
http://www.mysite.com/watch?v=Dxdotx3iT1
and want to redirect to
http://www.mysite.com/index.php?page=videos&section=view&v=Dxdotx3iT1
Can't seem to figure out the mod rewrite. Also using a ? I believe tells it to do something.
Any help would be appreciated.
You need to adjust your RewriteRule to include the query string using the [QSA] (query string attached) flag:
RewriteRule ^watch$ index.php?page=video&section=view [QSA]
RewriteCond %{QUERY_STRING} ^v=(.+)
RewriteRule ^watch /index\.php?page=videos&section=view&v=%1 [QSA,R=301,L]
None of these answers worked for me, so in the end I found through trial and error the following worked for me;
The RewriteRule to get my URL to look like this https://www.example.com/video/watch?v=UnIq3Id follows;
RewriteRule ^video\/watch\?*$ index.php?page=video [L,QSA]
I found that the following rule I had previously set up to make my URL look like this https://www.example.com/video/UnIq3Id interfered with my redirecting;
RewriteRule ^/?([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ index.php?page=$1&v=$2
Simply commenting it out fixed the issue, as follows;
#RewriteRule ^/?([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ index.php?page=$1&v=$2
The RewriteRule to get my URL to look like this https://www.example.com/watch?v=UnIq3Id is as follows;
RewriteRule ^watch\?*$ index.php?page=video [L,QSA]
I found that the following rule I had previously set up to make my URL look like this https://www.example.com/video/ interfered with my redirecting;
RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?page=$1 [NC]
Simply commenting it out fixed the issue, as follows;
#RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?page=$1 [NC]
Hope it helped someone and saved you the headache I had, people are not so forthcoming on this issue at times How do you write an htaccess RewriteRule to make my urls work like youtube?.

Categories