I am using mod-rewrite to make pretty urls. For example http://centraltrack.com/Nightlife/5936/That-Happened/Scenes-From-Friday-Nights-Pop-That-Party-at-Sons-of-Hermann-Hall is using the page http://centraltrack.com/_source/article.php?id=5936. Now when you share a link on facebook it links to the error page instead of the correct page. The Facebook linter pulls in all the correct data, so I'm not sure how to fix the issue.
Again, when you share the not pretty url above, it works and when you share the pretty one, it links to the error page instead. Everything on the site works fine, sharing on Facebook just doesn't work.
Here is how I'm rewriting the links in my .htaccess file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^_source - [L]
RewriteRule ^images - [L]
RewriteRule ^login - [L]
RewriteRule ^([A-Za-z]+)/([0-9]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ _source/article.php?id=$2 [NC,L]
Related
How do I make the redirects in go_router package work correctly when uploading the website to cPanel? For example when I type in the url www.website.com/contact I need it to open the /contact route on my app. It works great when hosting locally and when I host it to Firebase with the rewrites file (https://stackoverflow.com/a/71956918/12099062), but I am unable to make the redirects work in cPanel.
I have tried configuring the Redirects in cPanel, but if I redirect any page to www.website.com it just moves to the main page and if I redirect it to www.website.com/index.html it just shows Exception: Bad State: No Element.
Any help is really appreciated!
I managed to make it work by following a React app tutorial (Deploy / Host your React App with cPanel in Under 5 Minutes). I needed to manually add these contents to the .htaccess file in cPanel File Manager public_html folder (Note: You need to enable "Show hidden files" in order to see that file and if it does not exist, just create it).
Here is the complete .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
I have done a webpage with flutter. I have removed the hash symbol from url using setPathUrlStrategy() method. But after hosting to the server the hash is removed from the url but when the page is refreshed it shows 404 error page. I have found different solution like changing the <base href='/'> in index.html to <base href='./'> but done these all solution but not working. I have also tried creating a 404 and .htaccess file and put it in the same level of index.html in web folder of flutter this too doesnt work.
i am use Nginx web server and sample of my web url is as example.demo.com
the sample of my .htaccess file is as below:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
```
If anyone has any idea please help
I'm trying to enable direct url handling on my Flutter app. I am using beamer and the app works as expected with deep linking within an app emulator, and when using the chrome web browser emulator through vscode.
When I publish the code though, only the main page works. Directly accessing the url doesn't.
When I switch back to the /#/ strategy, everything works and I can access anywhere in the app directly.
This means that the app is not loaded and only the Apache webserver is returning a 404 because it does not recognize index.html of the flutter jS file to be a cgi.
Awhile back I worked with php and there was a way to access url's without using extensions and an override in httpd.conf setting.
Has anyone got this working for flutter navigation 2.0 compiled for web on an apache webserver?
Thanks
create a .htaccess file in the root directory:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
</IfModule>
Edit httpd.conf for that root directory:
DocumentRoot "/Users/myname/myapp/build/web"
<Directory "/Users/myname/myapp/build/web">
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
Visit: yoursite.com/path/to/flutter/page or wherever you have a route parser
I was able to successfully deploy my web app in apache server(wamp) locally. So initially my URL looks like http://somehost.com/dshrestha/ and I can navigate to various routes for eg. http://somehost.com/dshrestha/home, http://somehost.com/dshrestha/contact etc via navigation links but then when I refresh the page on any of the routes, I get 404 Not Found error.
How can I overcome this issue? i even tried to redirect all requests to index.html by creating htaccess file but no luck. Thanks.
I had the same problem, but I found the solution in the next answer:
https://stackoverflow.com/a/28630973/4425050
Change the locationType from auto --> to hash
Ok turned out it was an .htaccess thing I had to fix. Added these in my .htaccess to get things working
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !(?=jpg|png|gif|js|css|pdf|docx|htm)
RewriteRule ^(.*)$ index.html
its an old post, however, to make sure you can use bootstrap glyphicon and any other file that pg|png|gif|js|css|pdf|docx|htm, replace
RewriteCond %{REQUEST_FILENAME} !(?=jpg|png|gif|js|css|pdf|docx|htm)
with this
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
I am using Zend Framework and running into issues where myAction() is called twice. After spending many hours looking for other developers with same experience it seems that there are some main issues that people have solved. Either:
-*.css / *.js file or favicon is not found, so I tailed the apache access log fiel with no thing to show for.
-Then I looked for images that did not exist that were referenced in any css. No luck there as well.
-Lastly I found that people using ZFDebug were running into issues, but since I am not using that or have it installed this is something I cannot troubleshoot.
Please if anyone has any idea of what I can try to resolve the issue I would grateful if you would share this with me.
UPDATE:
kinghfb and Phil,
Thank you very much for your replies.
Your information was very clear and all very good suggestions. I double checked all my css and js files and since I don't really use partials but have view helpers that was an easy check as well. All were at least 4k and none were empty. I also, tried what Phil suggested changed:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
to:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Which also did not solve my problem. I did fail to say earlier that when I disable layout in the action it runs only once. Any other suggestions?
I ran into this same problem, and found solutions similar to what you describe (Zend Debug, favicon.ico etc etc). However, I wasn't running any of these things.
What you need to check is that all the requested files actually exist and are greater than 0 bytes (JS, CSS, images, and -importantly- template files), otherwise the system won't find it and try to Bootstrap the app again. This is because the default mod_rewrite settings only bypass the bootstrap when the requested file is > 0 bytes.
Hopefully that's clear and helped :)
Thanks really much for this answer kinghfb, you saved me lots of time...
In my layout file I had 3 of those (that causes the controller to execute 3 times) :
<img src="path/path/file.jpg" >
I had to do this instead :
<img src="/path/path/file.jpg" >
The way I've found this is by writing to a file in my controller (doing only echo won't show it)