Topic redirects with addition characters - php

I really appreciate the help you guys
have been rendering to people.
I am using Pretty URL for SMF.
I want to redirect a topic to another but the URL for the page which the Pretty URL gets the content it displays is attached to the URL after redirection.
Here is an example.
I used this in my .htaccess.
Redirect 301 /2030/ https://google.com
I am just testing, I am trying to redirect http://example.com/2030 to Google site address.
but when I redirect to Google, the URL contains:
https://www.google.com/?pretty;board=2030.0
pretty; board=2030 is the page which the http://example.com/2030 gets the content it displays.
How can I redirect to https://www.google.com without the
pretty;board=2030 showing.
Here is my entire .htaccess
# PRETTYURLS MOD BEGINS
# Pretty URLs mod
# http://code.google.com/p/prettyurls/
# .htaccess file generated automatically on: September 1, 2018, 16:50
RewriteEngine on
Redirect 301 /2030 https://google.com
RewriteBase /
# Rules for: profiles
RewriteRule ^profile/([^/]+)/?$ ./index.php?pretty;action=profile;user=$1 [L,QSA]
# Rules for: actions
RewriteRule ^(activate|admin|announce|attachapprove|buddy|calendar|clock|collapse)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(coppa|credits|deletemsg|display|dlattach|editpoll|editpoll2|emailuser)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(findmember|groups|help|helpadmin|im|jseditor|jsmodify|jsoption)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(lock|lockvoting|login|login2|logout|markasread|mergetopics|mlist)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(moderate|modifycat|modifykarma|movetopic|movetopic2|notify|notifyboard|openidreturn)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(pm|post|post2|printpage|profile|quotefast|quickmod|quickmod2)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(recent|register|register2|reminder|removepoll|removetopic2|reporttm|requestmembers)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(restoretopic|search|search2|sendtopic|smstats|suggest|spellcheck|splittopics)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(stats|sticky|theme|trackip|about:mozilla|about:unknown|unread|unreadreplies)/?$ ./index.php?pretty;action=$1 [L,QSA]
RewriteRule ^(verificationcode|viewprofile|vote|viewquery|viewsmfile|who|\.xml|xmlhttp)/?$ ./index.php?pretty;action=$1 [L,QSA]
# Rules for: boards
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;board=$1.0 [L,QSA]
RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ ./index.php?pretty;board=$1.$2 [L,QSA]
# Rules for: topics
RewriteRule ^([0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ ./index.php?pretty;topic=$1.0 [L,QSA]
RewriteRule ^([0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ ./index.php?pretty;topic=$1.$3 [L,QSA]
# PRETTYURLS MOD ENDS

Replace
Redirect 301 /2030 https://google.com
with
RewriteRule "(.)*/2030$" "https://google.com" [R=301,L]

Related

Htaccess redirect seems not working with php file extension to seo friendly (no extension) url

One of my website's old URL structures is like this:
https://example.com/login.php
or,
https://example.com/login.php?redirect=https://example.com
or,
https://example.com/register.php
after rebuilding the URLs, the URLs look like this:
https://example.com/login
or,
https://example.com/login?redirect=https://example.com
or,
https://example.com/register
Now when the user/visitor uses the old URL https://example.com/login.php, I want to redirect to the https://example.com/login page. How can I do it?
FYI, currently, my .htaccess file has the following content:
AddDefaultCharset UTF-8
ErrorDocument 404 /error-404/
##
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
## Allow a few SEO Files direct access.
RewriteRule ^robots.txt?$ robots.txt [L]
RewriteRule ^ads.txt?$ ads.txt [L]
RewriteRule ^sellers.json?$ sellers.json [L]
## Avoid rewriting rules for the admin section
RewriteRule ^(admin|resources)($|/) - [L]
## Set Ajax Request File
RewriteRule ^kahuk-ajax.php?$ kahuk-ajax.php? [L,QSA]
## Set controller with id
RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?con=$1&id=$2 [L,QSA]
## Set controller with slug
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?con=$1&slug=$2 [L,QSA]
## For paging
RewriteRule ^([^/]+)/page/([0-9]+)/?$ index.php?con=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/page/([0-9]+)/?$ index.php?con=$1&slug=$2&page=$3 [L,QSA]
## Set controller for only one parameter
RewriteRule ^page/([^/]+)/?$ index.php?con=page&slug=$1 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?con=$1 [L,QSA]
## Set home page
RewriteRule ^/?$ index.php?con=home [L]
You can insert this rule just below RewriteBase / line to remove .php extension:
# To externally redirect /afile.php to /afile
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule !^admin/ /%1 [R=301,NE,L,NC]

htaccess url-rewriter page not found

i work in localhost and i need to rewrite url, when i write the url rewrited, a page like : 404 Not found This page not found on this server ...
But the directory is good
I already try to uncomment the line for mod_rewrite in httpdconf.conf
but not work
# URL REWRITING
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^esthetique$ /view/frontend/aestheticView.php [L]
RewriteRule ^forfait-fiancee-normal$ /view/frontend/forfaitFianceeBasicView.php [L]
RewriteRule ^forfait-mariee-normal$ /view/frontend/forfaitMarieeBasicView.php [L]
RewriteRule ^forfait-mariee-belle-dun-soir$ /view/frontend/forfaitMarieePremiumView.php [L]
RewriteRule ^forfaits$ /view/frontend/forfaitsView.php [L]
RewriteRule ^coiffure$ /view/frontend/hairView.php [L]
RewriteRule ^accueil$ /view/frontend/homeView.php [L]
RewriteRule ^mentions-legales$ /view/frontend/legalsView.php [L]
RewriteRule ^maquillage$ /view/frontend/makeupView.php [L]
RewriteRule ^packs-reductions$ /view/frontend/packsView.php [L]
RewriteRule ^politique$ /view/frontend/politiqueView.php [L]
When i go to the url mywebsite.ex/esthetique
He tell me :The requested URL /view/frontend/aestheticView.php was not found on this server.
And he work's when is online

htaccess doesn't work as expected

I have an htaccess rewrite URL as below:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^my-page\.html$ /my-page.php [L]
RewriteRule ^my-page/([^/]*)\.html$ /level1.php?num=$1 [L]
RewriteRule ^my-page/([^/]*)/([^/]*)\.html$ /level2.php?level1=$1&level2=$2 [L]
RewriteRule ^([^/]*)\.html$ /level3.php?level3=$1 [L]
These rules above rewrite URLs from mywebsite.com/my-page.php to mywebsite.com/my-page.html.
Now, what I want to achieve is mywebsite.com/my-page/ to be redirected to mywebsite.com/my-page.php (which in turn rewrites to mywebsite.com/my-page.html).
What I have tried, I created a directory "my-page" and tried to redirect requests from mywebsite.com/my-page/ to /my-page.html.
I don't know what went wrong. I can see in the network tab that a request is made to /my-page/ and gets rewritten to mywebsite.com/my-page.htmlmy-page/, which gives a 302 Status ☹
Please help! Thank you.
You can try use RedirectMatch to achieve this.
Redirect to my-page.php:
RedirectMatch 301 ^/my-page/ http://mywebsite.com/my-page.php
or straight away to my-page.html if this is your goal:
RedirectMatch 301 ^/my-page/ http://mywebsite.com/my-page.html
or, what will be best - change the code responsible for mywebsite.com/my-page.htmlmy-page/, but I can't see it in question you have asked :)
Please give the following a try. Brief descriptions are found in the comments for each section.
RewriteEngine On
# Trim www.
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R=301,L]
RewriteBase /
# Redirect /my-page[/] to /my-page.html
# >> Note: change 302 to 301 to make permanent
RewriteRule ^my-page/?$ my-page.html [R=302,L]
# Allow existing files and directories
# Recommended to comment out the first line
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite *.html to respective page
RewriteRule ^my-page.html$ my-page.php [L]
RewriteRule ^my-page/([^/]*).html$ level1.php?num=$1 [L]
RewriteRule ^my-page/([^/]*)/([^/]*).html$ level2.php?level1=$1&level2=$2 [L]
RewriteRule ^([^/]*).html$ level3.php?level3=$1 [L]
The important part here is that you do the required redirect before any other rewrites (except the www. removal).
Also, you previously had the two conditions which stated that if the request was not for a file or directory, then proceed with the next rule, but that wouldn't have accounted for the last two rules. As such, this version tells Apache to stop everything if the request is for an existing file or directory. I would recommend, for security purposes, that you comment out the line that checks for existing directories.

I have masked the url now i want to change the masked url

Few days back I had posted a question related to this and I got some great push. Also I did some experimenting and research and achieved some good result. here is what exactly I have achieved. I put this in my .htaccess in my folder -'folder':
RewriteEngine On
#Look for the word "post" and take everything after "post" and store it in $1
RewriteRule post(.+)$ something.php?file=$1 [L]
# allow public pages
RewriteRule ^index.php$ - [L]
RewriteRule ^style.css$ - [L]
RewriteRule ^bg.png$ - [L]
RewriteRule ^cat_bgg.gif$ - [L]
RewriteRule ^cat_bgr.png$ - [L]
RewriteRule ^h1_bg.gif$ - [L]
RewriteRule ^hd_bg.png$ - [L]
RewriteRule ^menu_bg.png$ - [L]
# serve everyone from specific-domain or specific-user-agent
RewriteCond %{HTTP_REFERER} ^http?://www.abc.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^specific-user-agent$
RewriteRule ^ - [L]
# everybody else receives a forbidden
RewriteRule ^ - [F]
ErrorDocument 403 /index.php
So this is how it is working now:
I put a link on:
www.abc.com
as
www.xyz.com/folder/post(somecode)
When someone clicks this link, as per .htaccess 'somecode' is taken and stored in $1 and processes:
www.xyz.com/folder/something.php?file=$1
and displays this content. But the url shown in browser is:
www.xyz.com/folder/post(somecode).
Now this is what I want to do. Instead of displaying:
www.xyz.com/folder/post(somecode)
can i show something nice like
www.xyz.com/somethingnice
or
www.xyz.com/folder/someword
How do I do this? Should I add something after the line
RewriteRule post(.+)$ something.php?file=$1 [L]
Or is there some other method?

Rewriterule - urls dont change in the browser bar

It's very strange to me, but:
I have a website with guestbook-add.php. I want to show it to the visitors as gasterbuch.html.
So I have written in .htaccess (my real domain has been changed in that listing to http://mywebsite.com/ of course):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ http://mywebsite.com/index.php [L]
RewriteRule ^gasterbuch.html$ http://mywebsite.com/guestbook-list.php
RewriteRule ^eintrag-hinzufugen.html$ http://mywebsite.com/guestbook-add.php
</IfModule>
Now, when I type in the browser http://mywebsite.com/gasterbuch.html, I see the text generated by guestbook-add.php (which is fine).
But in the browser url bar, I see http://mywebsite.com/guestbook-add.php instead of http://mywebsite.com/gasterbuch.html (like it was the 302 redirect).
What am I doing wrong?
Changing
RewriteRule ^index.html$ http://mywebsite.com/index.php [L]
RewriteRule ^gasterbuch.html$ http://mywebsite.com/guestbook-list.php
RewriteRule ^eintrag-hinzufugen.html$ http://mywebsite.com/guestbook-add.php
to
RewriteRule ^index.html$ /index.php [L]
RewriteRule ^gasterbuch.html$ /guestbook-list.php [L]
RewriteRule ^eintrag-hinzufugen.html$ /guestbook-add.php [L]
should work.

Categories